diff options
author | XANTRONIX Development | 2023-09-10 23:13:51 -0400 |
---|---|---|
committer | XANTRONIX Development | 2023-09-10 23:13:51 -0400 |
commit | e1e296f8ee6b11b0f7c0af961fd12b3562595c68 (patch) | |
tree | 6ef818814466b2982a1ca44b8044bf1f8da65fe6 | |
parent | 74095ec4d92c4e70352d199447790b3fe096d4a1 (diff) | |
download | zxdump-e1e296f8ee6b11b0f7c0af961fd12b3562595c68.tar.gz zxdump-e1e296f8ee6b11b0f7c0af961fd12b3562595c68.tar.bz2 zxdump-e1e296f8ee6b11b0f7c0af961fd12b3562595c68.zip |
WOO IT WORKS A LOT BETTER WHEN I ACTUALLY READ
-rw-r--r-- | main.c | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -37,19 +37,29 @@ static void usage(int argc, char **argv, char *message, ...) { exit(1); } -static inline size_t utf8_encode(uint8_t *buf, uint16_t codepoint) { +static inline size_t utf8_encode(uint8_t *buf, uint32_t codepoint) { if ((codepoint & 0x007f) == codepoint) { - buf[0] = codepoint & 0xff; + buf[0] = codepoint & 0x007f; + return 1; } else if ((codepoint & 0x07ff) == codepoint) { - buf[0] = (codepoint & 0x07c0) >> 6; - buf[1] = codepoint & 0x003f; + buf[0] = 0xc0 | ((codepoint & 0x07c0) >> 6); + buf[1] = 0x80 | (codepoint & 0x003f); + return 2; } else if ((codepoint & 0xffff) == codepoint) { - buf[0] = (codepoint & 0xf000) >> 12; - buf[1] = (codepoint & 0x0fc0) >> 6; - buf[2] = codepoint & 0x003f; + buf[0] = 0xe0 | ((codepoint & 0xf000) >> 12); + buf[1] = 0x80 | ((codepoint & 0x0fc0) >> 6); + buf[2] = 0x80 | (codepoint & 0x003f); + return 3; + } else { + buf[0] = 0xf0 | ((codepoint & 0x1c0000) >> 18); + buf[1] = 0x80 | ((codepoint & 0x03f000) >> 12); + buf[2] = 0x80 | ((codepoint & 0x000fc0) >> 6); + buf[3] = 0x80 | (codepoint & 0x00003f); + + return 4; } } |