diff options
author | default <nobody@localhost> | 2024-02-15 17:44:28 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2024-02-15 17:44:28 +0100 |
commit | b75e44afb38bef99bc932942ff4ba4286b774507 (patch) | |
tree | 07a3d3a1bf552bf6287c20e9ec7e6e5bbe73774c /xs_unicode.h | |
parent | 263e239653b79d230a7546b9db89ff71dc0f2a53 (diff) |
Backport from xs.
Diffstat (limited to 'xs_unicode.h')
-rw-r--r-- | xs_unicode.h | 10 |
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 @@ #define _XS_UNICODE_H int _xs_utf8_enc(char buf[4], unsigned int cpoint); + int xs_is_utf8_cont_byte(char c); unsigned int xs_utf8_dec(char **str); int xs_unicode_width(unsigned int cpoint); int xs_is_surrogate(unsigned int cpoint); @@ -58,6 +59,13 @@ int _xs_utf8_enc(char buf[4], unsigned int cpoint) } +int xs_is_utf8_cont_byte(char c) +/* returns true if c is an utf8 continuation byte */ +{ + return ((c & 0xc0) == 0x80); +} + + unsigned int xs_utf8_dec(char **str) /* decodes an utf-8 char inside str and updates the pointer */ { @@ -86,7 +94,7 @@ unsigned int xs_utf8_dec(char **str) } /* process the continuation bytes */ - while (cb > 0 && *p && (*p & 0xc0) == 0x80) + while (cb > 0 && *p && xs_is_utf8_cont_byte(*p)) cpoint |= (*p++ & 0x3f) << (--cb * 6); /* incomplete or broken? */ |