scrolling text scrolling, unicode-aware strlen
This commit is contained in:
@@ -16,6 +16,9 @@ uint16_t unicodeToWchar16(const unsigned char* utf8, size_t maxLen); /
|
||||
// return nullptr at end of input
|
||||
const unsigned char* nextUnicode(const unsigned char* utf8, size_t maxLen); // unicodetool.cpp
|
||||
|
||||
// unicode-aware string length
|
||||
size_t strlenUC(const unsigned char* utf8);
|
||||
|
||||
// translates unicode 2-byte (UTF-16) "code point" into corresponding character in codepage 437 (IBM PC aka PC-8)
|
||||
uint16_t wchar16ToCodepage437(uint16_t wideChar); // codepage437.cpp
|
||||
|
||||
|
||||
@@ -72,4 +72,15 @@ const unsigned char* nextUnicode(const unsigned char* utf8, size_t maxLen) {
|
||||
else return utf8 + codeLength; // success: advance stream
|
||||
}
|
||||
|
||||
// unicode-aware string length
|
||||
size_t strlenUC(const unsigned char* utf8) {
|
||||
if ((utf8 == nullptr) || (utf8[0] == '\0')) return 0;
|
||||
size_t maxLen = strlen((const char *)utf8);
|
||||
size_t letters = 0;
|
||||
for(const unsigned char* now = utf8; now != nullptr && now[0] != '\0'; now = nextUnicode(now, maxLen)) // iterates over utf-8 and count letters
|
||||
letters++;
|
||||
|
||||
return letters;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user