scrolling text scrolling, unicode-aware strlen

This commit is contained in:
Frank
2025-11-20 18:05:53 +01:00
parent 45f793b338
commit 4a4887aaba
3 changed files with 27 additions and 4 deletions

View File

@@ -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

View File

@@ -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