Added SDL_StepBackUTF8()
This commit is contained in:
@@ -1176,6 +1176,7 @@ SDL3_0.0.0 {
|
||||
SDL_wcsnstr;
|
||||
SDL_wcsstr;
|
||||
SDL_wcstol;
|
||||
SDL_StepBackUTF8;
|
||||
# extra symbols go here (don't modify this line)
|
||||
local: *;
|
||||
};
|
||||
|
||||
@@ -1201,3 +1201,4 @@
|
||||
#define SDL_wcsnstr SDL_wcsnstr_REAL
|
||||
#define SDL_wcsstr SDL_wcsstr_REAL
|
||||
#define SDL_wcstol SDL_wcstol_REAL
|
||||
#define SDL_StepBackUTF8 SDL_StepBackUTF8_REAL
|
||||
|
||||
@@ -1207,3 +1207,4 @@ SDL_DYNAPI_PROC(size_t,SDL_wcsnlen,(const wchar_t *a, size_t b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(wchar_t*,SDL_wcsnstr,(const wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(wchar_t*,SDL_wcsstr,(const wchar_t *a, const wchar_t *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(long,SDL_wcstol,(const wchar_t *a, wchar_t **b, int c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(Uint32,SDL_StepBackUTF8,(const char *a, const char **b),(a,b),return)
|
||||
|
||||
@@ -265,6 +265,26 @@ Uint32 SDL_StepUTF8(const char **pstr, size_t *pslen)
|
||||
return result;
|
||||
}
|
||||
|
||||
Uint32 SDL_StepBackUTF8(const char *start, const char **pstr)
|
||||
{
|
||||
if (!pstr || *pstr <= start) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Step back over the previous UTF-8 character
|
||||
const char *str = *pstr;
|
||||
do {
|
||||
if (str == start) {
|
||||
break;
|
||||
}
|
||||
--str;
|
||||
} while ((*str & 0xC0) == 0x80);
|
||||
|
||||
size_t length = (*pstr - str);
|
||||
*pstr = str;
|
||||
return StepUTF8(&str, length);
|
||||
}
|
||||
|
||||
#if (SDL_SIZEOF_WCHAR_T == 2)
|
||||
static Uint32 StepUTF16(const Uint16 **_str, const size_t slen)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user