From 32c1789c73d544bf1f2652c10ae231899c4bdb0b Mon Sep 17 00:00:00 2001 From: gagarinlg Date: Sat, 11 Jun 2022 11:43:27 +0200 Subject: [PATCH] fix greater or equal char for B&W radios add support for three byte UTF-8 sequences to utf-8 converter --- radio/src/gui/common/stdlcd/utf8.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/radio/src/gui/common/stdlcd/utf8.cpp b/radio/src/gui/common/stdlcd/utf8.cpp index 14623cc9d..4fd451b91 100644 --- a/radio/src/gui/common/stdlcd/utf8.cpp +++ b/radio/src/gui/common/stdlcd/utf8.cpp @@ -73,16 +73,29 @@ static unsigned char lookup_utf8_mapping(wchar_t w) unsigned char map_utf8_char(const char*& s, uint8_t& len) { - unsigned char c = *s; - if ((c & 0xC0) == 0xC0) { - wchar_t w = (c & 0x1F) << 6; + uint8_t c = *s; + if (((c & 0xE0) == 0xC0) || ((c & 0xF0) == 0xE0)) { if (!len) return 0; - len--; s++; c = *s; - w |= c & 0x3F; + wchar_t w = 0; + if((c & 0xE0) == 0xC0) // two byte sequence + { + w = (c & 0x1F) << 6; + len--; s++; c = *s; + w |= c & 0x3F; + } else if ((c & 0xF0) == 0xE0) { // three byte sequence + w = (c & 0x0F) << 12; + len--; s++; c = *s; + if (!len) return 0; + w |= (c & 0x3F) << 6; + len--; s++; c = *s; + w |= c & 0x3F; + } // TODO: use constants if (w >= 0x80 && w <= 0x94) { // extra chars return (unsigned char)w; } + if(w == L'≥') + return '}'; #if !defined(NO_UTF8_LUT) return lookup_utf8_mapping(w); #else