mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-02-15 16:14:05 +00:00
Only convert the result of XLookupString() if it's not already UTF-8
Fixes https://github.com/libsdl-org/SDL/issues/7766
(cherry picked from commit 491ae20d96)
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
#define UTF8_IsLeadByte(c) ((c) >= 0xC0 && (c) <= 0xF4)
|
||||
#define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF)
|
||||
|
||||
static unsigned UTF8_TrailingBytes(unsigned char c)
|
||||
static size_t UTF8_TrailingBytes(unsigned char c)
|
||||
{
|
||||
if (c >= 0xC0 && c <= 0xDF) {
|
||||
return 1;
|
||||
@@ -621,6 +621,42 @@ SDL_utf8strnlen(const char *str, size_t bytes)
|
||||
return retval;
|
||||
}
|
||||
|
||||
SDL_bool SDL_utf8valid(const char *str, size_t bytes)
|
||||
{
|
||||
while (*str && bytes > 0) {
|
||||
Uint8 ch = (Uint8)*str;
|
||||
|
||||
if (ch <= 0x7F) {
|
||||
++str;
|
||||
--bytes;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (UTF8_IsLeadByte(ch)) {
|
||||
size_t left = UTF8_TrailingBytes(ch);
|
||||
if (bytes < left) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
++str;
|
||||
--bytes;
|
||||
|
||||
while (left-- > 0) {
|
||||
ch = (Uint8)*str;
|
||||
if (!UTF8_IsTrailingByte(ch)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
++str;
|
||||
--bytes;
|
||||
}
|
||||
} else {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
size_t
|
||||
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user