summaryrefslogtreecommitdiff
path: root/xs_unicode.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--xs_unicode.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/xs_unicode.h b/xs_unicode.h
index c7d6190..f5880f0 100644
--- a/xs_unicode.h
+++ b/xs_unicode.h
@@ -8,6 +8,9 @@
8 xs_str *xs_utf8_enc(xs_str *str, unsigned int cpoint); 8 xs_str *xs_utf8_enc(xs_str *str, unsigned int cpoint);
9 unsigned int xs_utf8_dec(char **str); 9 unsigned int xs_utf8_dec(char **str);
10 int xs_unicode_width(unsigned int cpoint); 10 int xs_unicode_width(unsigned int cpoint);
11 int xs_is_surrogate(unsigned int cpoint);
12 unsigned int xs_surrogate_dec(unsigned int p1, unsigned int p2);
13 unsigned int xs_surrogate_enc(unsigned int cpoint);
11 unsigned int *_xs_unicode_upper_search(unsigned int cpoint); 14 unsigned int *_xs_unicode_upper_search(unsigned int cpoint);
12 unsigned int *_xs_unicode_lower_search(unsigned int cpoint); 15 unsigned int *_xs_unicode_lower_search(unsigned int cpoint);
13 #define xs_unicode_is_upper(cpoint) (!!_xs_unicode_upper_search(cpoint)) 16 #define xs_unicode_is_upper(cpoint) (!!_xs_unicode_upper_search(cpoint))
@@ -138,6 +141,32 @@ int xs_unicode_width(unsigned int cpoint)
138} 141}
139 142
140 143
144/** surrogate pairs **/
145
146int xs_is_surrogate(unsigned int cpoint)
147/* checks if cpoint is the first element of a Unicode surrogate pair */
148{
149 return cpoint >= 0xd800 && cpoint <= 0xdfff;
150}
151
152
153unsigned int xs_surrogate_dec(unsigned int p1, unsigned int p2)
154/* "decodes" a surrogate pair into a codepoint */
155{
156 return 0x10000 | ((p1 & 0x3ff) << 10) | (p2 & 0x3ff);
157}
158
159
160unsigned int xs_surrogate_enc(unsigned int cpoint)
161/* "encodes" a Unicode into a surrogate pair (p1 in the MSB word) */
162{
163 unsigned int p1 = 0xd7c0 + (cpoint >> 10);
164 unsigned int p2 = 0xdc00 + (cpoint & 0x3ff);
165
166 return (p1 << 16) | p2;
167}
168
169
141#ifdef _XS_UNICODE_TBL_H 170#ifdef _XS_UNICODE_TBL_H
142 171
143/* include xs_unicode_tbl.h before this one to use these functions */ 172/* include xs_unicode_tbl.h before this one to use these functions */