Encapuslate UTF-8 decoder state in a struct

This commit is contained in:
Rangi
2026-07-03 19:35:23 -04:00
parent e3c594c250
commit 0996a2f5ed
5 changed files with 36 additions and 34 deletions
+4 -4
View File
@@ -42,9 +42,9 @@ static uint8_t const utf8d[] = {
};
// clang-format on
uint32_t decode(uint32_t *state, uint32_t *codep, uint8_t byte) {
uint32_t Utf8Decoder::update(uint8_t byte) {
uint8_t type = utf8d[byte];
*codep = *state != UTF8_ACCEPT ? (byte & 0b111111) | (*codep << 6) : (0xff >> type) & byte;
*state = utf8d[0x100 + *state + type];
return *state;
codepoint = state != UTF8_ACCEPT ? (byte & 0b111111) | (codepoint << 6) : (0xff >> type) & byte;
state = utf8d[0x100 + state + type];
return state;
}