all repos — mgba @ 04a81d2ec5bcd8b273482215864f1a3114b04543

mGBA Game Boy Advance Emulator

GUI: Properly support Unicode filenames
Jeffrey Pfau jeffrey@endrift.com
Sun, 01 Nov 2015 09:33:07 -0800
commit

04a81d2ec5bcd8b273482215864f1a3114b04543

parent

d357b9328505447b15cd442a89b5e8f54953e455

3 files changed, 10 insertions(+), 8 deletions(-)

jump to
M src/util/gui/font.csrc/util/gui/font.c

@@ -26,9 +26,9 @@ break;

default: break; } - size_t i; - for (i = 0; text[i]; ++i) { - char c = text[i]; + size_t len = strlen(text); + while (len) { + uint32_t c = utf8Char(&text, &len); GUIFontDrawGlyph(font, x, y, color, c); x += GUIFontGlyphWidth(font, c); }
M src/util/string.csrc/util/string.c

@@ -39,7 +39,7 @@ }

return last; } -static uint32_t _utf16Char(const uint16_t** unicode, size_t* length) { +uint32_t utf16Char(const uint16_t** unicode, size_t* length) { if (*length < 2) { *length = 0; return 0;

@@ -69,7 +69,7 @@ lowSurrogate -= 0xDC00;

return (highSurrogate << 10) + lowSurrogate + 0x10000; } -static uint32_t _utf8Char(const char** unicode, size_t* length) { +uint32_t utf8Char(const char** unicode, size_t* length) { if (*length == 0) { return 0; }

@@ -150,8 +150,8 @@ }

if (char1 > char2) { return 1; } - char1 = _utf16Char(&utf16, &utf16Length); - char2 = _utf8Char(&utf8, &utf8Length); + char1 = utf16Char(&utf16, &utf16Length); + char2 = utf8Char(&utf8, &utf8Length); } if (utf16Length == 0 && utf8Length > 0) { return -1;

@@ -172,7 +172,7 @@ while (true) {

if (length == 0) { break; } - uint32_t unichar = _utf16Char(&utf16, &length); + uint32_t unichar = utf16Char(&utf16, &length); size_t bytes = _toUtf8(unichar, buffer); utf8Length += bytes; if (utf8Length < utf8TotalBytes) {
M src/util/string.hsrc/util/string.h

@@ -21,6 +21,8 @@ char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len);

int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length); char* utf16to8(const uint16_t* utf16, size_t length); +uint32_t utf8Char(const char** unicode, size_t* length); +uint32_t utf16Char(const uint16_t** unicode, size_t* length); int hexDigit(char digit); const char* hex32(const char* line, uint32_t* out);