refactor(ui): dedupe UTF-8 codepoint decoder

Three copies of the same routine: DisplayDriver::decodeCodepoint (added
in the FullscreenMsgView wrap fix) plus per-driver duplicates in
SH1106Display and GxEPDDisplay. Consolidate on DisplayDriver and have
translateUTF8Static also route through it instead of its own inline
decoder. Net: 63 lines removed, single source of truth.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-05-24 20:25:35 +02:00
co-authored by Claude Sonnet 4.6
parent 74764aed2b
commit 52a7081a13
5 changed files with 8 additions and 71 deletions
+4 -15
View File
@@ -134,23 +134,12 @@ public:
size_t j = 0;
const uint8_t* p = (const uint8_t*)src;
while (*p && j < dest_size - 1) {
uint8_t c = *p++;
if (c < 0x80) {
if (*p < 0x80) {
uint8_t c = *p++;
if (c >= 32) dest[j++] = c;
} else {
uint32_t cp = c;
if ((c & 0xE0) == 0xC0) {
cp = c & 0x1F;
if (*p) cp = (cp << 6) | (*p++ & 0x3F);
} else if ((c & 0xF0) == 0xE0) {
cp = c & 0x0F;
if (*p) cp = (cp << 6) | (*p++ & 0x3F);
if (*p) cp = (cp << 6) | (*p++ & 0x3F);
} else {
while (*p && (*p & 0xC0) == 0x80) p++;
dest[j++] = '\xDB';
continue;
}
uint32_t cp = decodeCodepoint(p);
// transliterateCodepoint already returns '\xDB' for unmapped values (incl. 0xFFFD).
dest[j++] = transliterateCodepoint(cp);
}
}