diff --git a/src/Lang.cpp b/src/Lang.cpp index b9c7f5d9c28..50c7a98b717 100644 --- a/src/Lang.cpp +++ b/src/Lang.cpp @@ -64,7 +64,7 @@ static int valid_utf8(StringRange data) int line = 1; while (c != data.end) { Uint32 chr; - int n = Text::conv_mb_to_wc(&chr, c); + int n = Text::utf8_decode_char(&chr, c); if (!n) return line; if (chr == '\n') ++line; c += n; diff --git a/src/gui/GuiTextEntry.cpp b/src/gui/GuiTextEntry.cpp index 2c1d942b442..a9c14e778ea 100644 --- a/src/gui/GuiTextEntry.cpp +++ b/src/gui/GuiTextEntry.cpp @@ -112,7 +112,7 @@ bool TextEntry::OnKeyPress(const SDL_keysym *sym) if (unicode == '\n') ++m_newlineCount; char buf[4]; - int len = Text::conv_wc_to_mb(unicode, buf); + int len = Text::utf8_encode_char(unicode, buf); m_text.insert(m_cursPos, buf, len); SetCursorPos(m_cursPos+len); changed = true; diff --git a/src/gui/GuiTextLayout.cpp b/src/gui/GuiTextLayout.cpp index 0407d22cf40..3058478eb57 100644 --- a/src/gui/GuiTextLayout.cpp +++ b/src/gui/GuiTextLayout.cpp @@ -72,7 +72,7 @@ TextLayout::TextLayout(const char *_str, RefCountedPtr font, } Uint32 chr; - int n = Text::conv_mb_to_wc(&chr, &str[i]); + int n = Text::utf8_decode_char(&chr, &str[i]); assert(n); i += n; diff --git a/src/text/TextSupport.cpp b/src/text/TextSupport.cpp index 74ff9a07d21..e9fedc13a95 100644 --- a/src/text/TextSupport.cpp +++ b/src/text/TextSupport.cpp @@ -4,7 +4,7 @@ namespace Text { // returns num bytes consumed, or 0 for end/bogus -int conv_mb_to_wc(Uint32 *chr, const char *src) +int utf8_decode_char(Uint32 *chr, const char *src) { unsigned int c = *(reinterpret_cast(src)); if (!c) { *chr = c; return 0; } @@ -37,7 +37,7 @@ int conv_mb_to_wc(Uint32 *chr, const char *src) // buf: a character buffer, which must have space for at least 4 bytes // (i.e., assigning to buf[3] must be a valid operation) // returns: number of bytes in the encoded character -int conv_wc_to_mb(Uint32 chr, char buf[4]) +int utf8_encode_char(Uint32 chr, char buf[4]) { unsigned char *ubuf = reinterpret_cast(buf); if (chr <= 0x7f) { diff --git a/src/text/TextSupport.h b/src/text/TextSupport.h index dc2bf03b36a..b58c7e510ca 100644 --- a/src/text/TextSupport.h +++ b/src/text/TextSupport.h @@ -11,14 +11,14 @@ namespace Text { // chr: pointer to output storage // src: multibyte string // returns: number of bytes swallowed, or 0 if end of string -int conv_mb_to_wc(Uint32 *chr, const char *src); +int utf8_decode_char(Uint32 *chr, const char *src); // encode one Unicode code-point as UTF-8 // chr: the Unicode code-point // buf: a character buffer, which must have space for at least 4 bytes // (i.e., assigning to buf[3] must be a valid operation) // returns: number of bytes in the encoded character -int conv_wc_to_mb(Uint32 chr, char buf[4]); +int utf8_encode_char(Uint32 chr, char buf[4]); } diff --git a/src/text/TextureFont.cpp b/src/text/TextureFont.cpp index 88c35e638c3..438bbfefe22 100644 --- a/src/text/TextureFont.cpp +++ b/src/text/TextureFont.cpp @@ -53,7 +53,7 @@ void TextureFont::MeasureString(const char *str, float &w, float &h) else { Uint32 chr; - int n = conv_mb_to_wc(&chr, &str[i]); + int n = utf8_decode_char(&chr, &str[i]); assert(n); i += n; @@ -61,7 +61,7 @@ void TextureFont::MeasureString(const char *str, float &w, float &h) if (str[i]) { Uint32 chr2; - n = conv_mb_to_wc(&chr2, &str[i]); + n = utf8_decode_char(&chr2, &str[i]); assert(n); FT_UInt a = FT_Get_Char_Index(m_face, chr); @@ -86,11 +86,11 @@ void TextureFont::MeasureCharacterPos(const char *str, int charIndex, float &cha float x = 0.0f, y = GetHeight(); int i = 0; Uint32 chr; - int len = conv_mb_to_wc(&chr, &str[i]); + int len = utf8_decode_char(&chr, &str[i]); while (str[i] && (i < charIndex)) { Uint32 nextChar; i += len; - len = conv_mb_to_wc(&nextChar, &str[i]); + len = utf8_decode_char(&nextChar, &str[i]); assert(!str[i] || len); // assert valid encoding if (chr == '\n') { @@ -143,7 +143,7 @@ int TextureFont::PickCharacter(const char *str, float mouseX, float mouseY) cons // read the next character i2 += charBytes; - charBytes = conv_mb_to_wc(&chr2, &str[i2]); + charBytes = utf8_decode_char(&chr2, &str[i2]); assert(!str[i2] || charBytes); // assert valid encoding float right; @@ -195,7 +195,7 @@ void TextureFont::RenderString(const char *str, float x, float y, const Color &c else { Uint32 chr; - int n = conv_mb_to_wc(&chr, &str[i]); + int n = utf8_decode_char(&chr, &str[i]); assert(n); i += n; @@ -204,7 +204,7 @@ void TextureFont::RenderString(const char *str, float x, float y, const Color &c if (str[i]) { Uint32 chr2; - n = conv_mb_to_wc(&chr2, &str[i]); + n = utf8_decode_char(&chr2, &str[i]); assert(n); FT_UInt a = FT_Get_Char_Index(m_face, chr); @@ -253,7 +253,7 @@ Color TextureFont::RenderMarkup(const char *str, float x, float y, const Color & else { Uint32 chr; - int n = conv_mb_to_wc(&chr, &str[i]); + int n = utf8_decode_char(&chr, &str[i]); assert(n); i += n; @@ -263,7 +263,7 @@ Color TextureFont::RenderMarkup(const char *str, float x, float y, const Color & // XXX kerning doesn't skip markup if (str[i]) { Uint32 chr2; - n = conv_mb_to_wc(&chr2, &str[i]); + n = utf8_decode_char(&chr2, &str[i]); assert(n); FT_UInt a = FT_Get_Char_Index(m_face, chr);