diff --git a/headers/os/support/UTF8.h b/headers/os/support/UTF8.h index d6d5a7067f..6260762c1c 100644 --- a/headers/os/support/UTF8.h +++ b/headers/os/support/UTF8.h @@ -61,6 +61,15 @@ _IMPEXP_TEXTENCODING status_t convert_from_utf8(uint32 dstEncoding, int32 *state, char substitute = B_SUBSTITUTE); +/*-------------------------------------------------------------*/ +/*------- Utility Functions -----------------------------------*/ + +// Suggested by BGA +inline uint32 utf8_char_len(uchar c) +{ + return (((0xE5000000 >> (((c) >> 3) & 0x1E)) & 3) + 1); +} + /*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/ diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp index 92eecd35b7..5a300f0430 100644 --- a/src/kits/support/String.cpp +++ b/src/kits/support/String.cpp @@ -36,6 +36,7 @@ #define DEBUG 1 #include #include +#include // Temporary Includes #include "string_helper.h" @@ -92,7 +93,9 @@ BString::CountChars() const count++; // Jump to next UTF8 character - for (; (*ptr & 0xc0) == 0x80; ptr++); + // for (; (*ptr & 0xc0) == 0x80; ptr++); + // ejaesler: BGA's nifty function + ptr += utf8_char_len(*ptr); } return count;