mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-03-06 19:29:55 +00:00
Don't bother re-encoding Latin1 characters in the ASCII range
(cherry picked from commit 6150b5b3cbde0e592c4ffe822f66aa5f9c90c3d9)
This commit is contained in:
parent
2660da6f5c
commit
4700fbcbdf
|
@ -27,9 +27,6 @@
|
||||||
/* Return the smallest power of 2 greater than or equal to 'x' */
|
/* Return the smallest power of 2 greater than or equal to 'x' */
|
||||||
extern int SDL_powerof2(int x);
|
extern int SDL_powerof2(int x);
|
||||||
|
|
||||||
/* Return whether the string is valid UTF8 */
|
|
||||||
extern SDL_bool SDL_utf8valid(const char *str, size_t bytes);
|
|
||||||
|
|
||||||
#endif /* SDL_utils_h_ */
|
#endif /* SDL_utils_h_ */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -621,42 +621,6 @@ SDL_utf8strnlen(const char *str, size_t bytes)
|
||||||
return retval;
|
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
|
size_t
|
||||||
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
|
||||||
{
|
{
|
||||||
|
|
|
@ -740,10 +740,22 @@ static Bool isReparentNotify(Display *display, XEvent *ev, XPointer arg)
|
||||||
ev->xreparent.serial == unmap->serial;
|
ev->xreparent.serial == unmap->serial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_bool IsHighLatin1(const char *string, int length)
|
||||||
|
{
|
||||||
|
while (length-- > 0) {
|
||||||
|
Uint8 ch = (Uint8)*string;
|
||||||
|
if (ch >= 0x80) {
|
||||||
|
return SDL_TRUE;
|
||||||
|
}
|
||||||
|
++string;
|
||||||
|
}
|
||||||
|
return SDL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static int XLookupStringAsUTF8(XKeyEvent *event_struct, char *buffer_return, int bytes_buffer, KeySym *keysym_return, XComposeStatus *status_in_out)
|
static int XLookupStringAsUTF8(XKeyEvent *event_struct, char *buffer_return, int bytes_buffer, KeySym *keysym_return, XComposeStatus *status_in_out)
|
||||||
{
|
{
|
||||||
int result = X11_XLookupString(event_struct, buffer_return, bytes_buffer, keysym_return, status_in_out);
|
int result = X11_XLookupString(event_struct, buffer_return, bytes_buffer, keysym_return, status_in_out);
|
||||||
if (result > 0 && !SDL_utf8valid(buffer_return, (size_t)result)) {
|
if (IsHighLatin1(buffer_return, result)) {
|
||||||
char *utf8_text = SDL_iconv_string("UTF-8", "ISO-8859-1", buffer_return, result);
|
char *utf8_text = SDL_iconv_string("UTF-8", "ISO-8859-1", buffer_return, result);
|
||||||
if (utf8_text) {
|
if (utf8_text) {
|
||||||
SDL_strlcpy(buffer_return, utf8_text, bytes_buffer);
|
SDL_strlcpy(buffer_return, utf8_text, bytes_buffer);
|
||||||
|
|
Loading…
Reference in a new issue