summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2023-09-10 23:13:51 -0400
committerXANTRONIX Development2023-09-10 23:13:51 -0400
commite1e296f8ee6b11b0f7c0af961fd12b3562595c68 (patch)
tree6ef818814466b2982a1ca44b8044bf1f8da65fe6
parent74095ec4d92c4e70352d199447790b3fe096d4a1 (diff)
downloadzxdump-e1e296f8ee6b11b0f7c0af961fd12b3562595c68.tar.gz
zxdump-e1e296f8ee6b11b0f7c0af961fd12b3562595c68.tar.bz2
zxdump-e1e296f8ee6b11b0f7c0af961fd12b3562595c68.zip
WOO IT WORKS A LOT BETTER WHEN I ACTUALLY READ
-rw-r--r--main.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/main.c b/main.c
index 69a3966..cf258c1 100644
--- a/main.c
+++ b/main.c
@@ -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;
}
}