Skip to content

Commit

Permalink
rename multibyte/widechar functions for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
robn committed Apr 16, 2012
1 parent 17d7504 commit f459d24
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Lang.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/GuiTextEntry.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/GuiTextLayout.cpp
Expand Up @@ -72,7 +72,7 @@ TextLayout::TextLayout(const char *_str, RefCountedPtr<Text::TextureFont> 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;

Expand Down
4 changes: 2 additions & 2 deletions src/text/TextSupport.cpp
Expand Up @@ -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<const unsigned char*>(src));
if (!c) { *chr = c; return 0; }
Expand Down Expand Up @@ -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<unsigned char*>(buf);
if (chr <= 0x7f) {
Expand Down
4 changes: 2 additions & 2 deletions src/text/TextSupport.h
Expand Up @@ -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]);

}

Expand Down
18 changes: 9 additions & 9 deletions src/text/TextureFont.cpp
Expand Up @@ -53,15 +53,15 @@ 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;

line_width += m_glyphs[chr].advx;

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);
Expand All @@ -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') {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit f459d24

Please sign in to comment.