summaryrefslogtreecommitdiff
path: root/xs_unicode.h
diff options
context:
space:
mode:
authorGravatar default2024-02-15 17:44:28 +0100
committerGravatar default2024-02-15 17:44:28 +0100
commitb75e44afb38bef99bc932942ff4ba4286b774507 (patch)
tree07a3d3a1bf552bf6287c20e9ec7e6e5bbe73774c /xs_unicode.h
parentMoved verified links to its own json file. (diff)
downloadpenes-snac2-b75e44afb38bef99bc932942ff4ba4286b774507.tar.gz
penes-snac2-b75e44afb38bef99bc932942ff4ba4286b774507.tar.xz
penes-snac2-b75e44afb38bef99bc932942ff4ba4286b774507.zip
Backport from xs.
Diffstat (limited to 'xs_unicode.h')
-rw-r--r--xs_unicode.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/xs_unicode.h b/xs_unicode.h
index 036c843..47e1101 100644
--- a/xs_unicode.h
+++ b/xs_unicode.h
@@ -5,6 +5,7 @@
5#define _XS_UNICODE_H 5#define _XS_UNICODE_H
6 6
7 int _xs_utf8_enc(char buf[4], unsigned int cpoint); 7 int _xs_utf8_enc(char buf[4], unsigned int cpoint);
8 int xs_is_utf8_cont_byte(char c);
8 unsigned int xs_utf8_dec(char **str); 9 unsigned int xs_utf8_dec(char **str);
9 int xs_unicode_width(unsigned int cpoint); 10 int xs_unicode_width(unsigned int cpoint);
10 int xs_is_surrogate(unsigned int cpoint); 11 int xs_is_surrogate(unsigned int cpoint);
@@ -58,6 +59,13 @@ int _xs_utf8_enc(char buf[4], unsigned int cpoint)
58} 59}
59 60
60 61
62int xs_is_utf8_cont_byte(char c)
63/* returns true if c is an utf8 continuation byte */
64{
65 return ((c & 0xc0) == 0x80);
66}
67
68
61unsigned int xs_utf8_dec(char **str) 69unsigned int xs_utf8_dec(char **str)
62/* decodes an utf-8 char inside str and updates the pointer */ 70/* decodes an utf-8 char inside str and updates the pointer */
63{ 71{
@@ -86,7 +94,7 @@ unsigned int xs_utf8_dec(char **str)
86 } 94 }
87 95
88 /* process the continuation bytes */ 96 /* process the continuation bytes */
89 while (cb > 0 && *p && (*p & 0xc0) == 0x80) 97 while (cb > 0 && *p && xs_is_utf8_cont_byte(*p))
90 cpoint |= (*p++ & 0x3f) << (--cb * 6); 98 cpoint |= (*p++ & 0x3f) << (--cb * 6);
91 99
92 /* incomplete or broken? */ 100 /* incomplete or broken? */