Simple Directmedia Layer
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Added SDL_StepBackUTF8()

+54 -1
+31 -1
include/SDL3/SDL_stdinc.h
··· 2472 2472 /** 2473 2473 * The Unicode REPLACEMENT CHARACTER codepoint. 2474 2474 * 2475 - * SDL_StepUTF8() reports this codepoint when it encounters a UTF-8 string 2475 + * SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they encounter a UTF-8 string 2476 2476 * with encoding errors. 2477 2477 * 2478 2478 * This tends to render as something like a question mark in most places. 2479 2479 * 2480 2480 * \since This macro is available since SDL 3.0.0. 2481 2481 * 2482 + * \sa SDL_StepBackUTF8 2482 2483 * \sa SDL_StepUTF8 2483 2484 */ 2484 2485 #define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD ··· 2527 2528 * \since This function is available since SDL 3.0.0. 2528 2529 */ 2529 2530 extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepUTF8(const char **pstr, size_t *pslen); 2531 + 2532 + /** 2533 + * Decode a UTF-8 string in reverse, one Unicode codepoint at a time. 2534 + * 2535 + * This will go to the start of the previous Unicode codepoint in the string, move `*pstr` to that location and return that codepoint. 2536 + * 2537 + * If the resulting codepoint is zero (already at the start of the string), it will not advance `*pstr` at all. 2538 + * 2539 + * Generally this function is called in a loop until it returns zero, 2540 + * adjusting its parameter each iteration. 2541 + * 2542 + * If an invalid UTF-8 sequence is encountered, this function returns 2543 + * SDL_INVALID_UNICODE_CODEPOINT. 2544 + * 2545 + * Several things can generate invalid UTF-8 sequences, including overlong 2546 + * encodings, the use of UTF-16 surrogate values, and truncated data. Please 2547 + * refer to 2548 + * [RFC3629](https://www.ietf.org/rfc/rfc3629.txt) 2549 + * for details. 2550 + * 2551 + * \param start a pointer to the beginning of the UTF-8 string. 2552 + * \param pstr a pointer to a UTF-8 string pointer to be read and adjusted. 2553 + * \returns the previous Unicode codepoint in the string. 2554 + * 2555 + * \threadsafety It is safe to call this function from any thread. 2556 + * 2557 + * \since This function is available since SDL 3.0.0. 2558 + */ 2559 + extern SDL_DECLSPEC Uint32 SDLCALL SDL_StepBackUTF8(const char *start, const char **pstr); 2530 2560 2531 2561 /** 2532 2562 * Convert a single Unicode codepoint to UTF-8.
+1
src/dynapi/SDL_dynapi.sym
··· 1176 1176 SDL_wcsnstr; 1177 1177 SDL_wcsstr; 1178 1178 SDL_wcstol; 1179 + SDL_StepBackUTF8; 1179 1180 # extra symbols go here (don't modify this line) 1180 1181 local: *; 1181 1182 };
+1
src/dynapi/SDL_dynapi_overrides.h
··· 1201 1201 #define SDL_wcsnstr SDL_wcsnstr_REAL 1202 1202 #define SDL_wcsstr SDL_wcsstr_REAL 1203 1203 #define SDL_wcstol SDL_wcstol_REAL 1204 + #define SDL_StepBackUTF8 SDL_StepBackUTF8_REAL
+1
src/dynapi/SDL_dynapi_procs.h
··· 1207 1207 SDL_DYNAPI_PROC(wchar_t*,SDL_wcsnstr,(const wchar_t *a, const wchar_t *b, size_t c),(a,b,c),return) 1208 1208 SDL_DYNAPI_PROC(wchar_t*,SDL_wcsstr,(const wchar_t *a, const wchar_t *b),(a,b),return) 1209 1209 SDL_DYNAPI_PROC(long,SDL_wcstol,(const wchar_t *a, wchar_t **b, int c),(a,b,c),return) 1210 + SDL_DYNAPI_PROC(Uint32,SDL_StepBackUTF8,(const char *a, const char **b),(a,b),return)
+20
src/stdlib/SDL_string.c
··· 265 265 return result; 266 266 } 267 267 268 + Uint32 SDL_StepBackUTF8(const char *start, const char **pstr) 269 + { 270 + if (!pstr || *pstr <= start) { 271 + return 0; 272 + } 273 + 274 + // Step back over the previous UTF-8 character 275 + const char *str = *pstr; 276 + do { 277 + if (str == start) { 278 + break; 279 + } 280 + --str; 281 + } while ((*str & 0xC0) == 0x80); 282 + 283 + size_t length = (*pstr - str); 284 + *pstr = str; 285 + return StepUTF8(&str, length); 286 + } 287 + 268 288 #if (SDL_SIZEOF_WCHAR_T == 2) 269 289 static Uint32 StepUTF16(const Uint16 **_str, const size_t slen) 270 290 {