summaryrefslogtreecommitdiff
path: root/xs_unicode.h
diff options
context:
space:
mode:
authorGravatar Louis Brauer2024-05-25 08:05:36 +0000
committerGravatar Louis Brauer2024-05-25 08:05:36 +0000
commit84a767dd0878013194ed7551b5ae6ef715e841a6 (patch)
tree9fb1b2b89e0bfbb4b8bf1e85d840c8653e646bb7 /xs_unicode.h
parentPrevent some browsers from caching servers basic auth request (diff)
parentBackport from xs (fix regex.h compilation with tcc). (diff)
downloadsnac2-84a767dd0878013194ed7551b5ae6ef715e841a6.tar.gz
snac2-84a767dd0878013194ed7551b5ae6ef715e841a6.tar.xz
snac2-84a767dd0878013194ed7551b5ae6ef715e841a6.zip
Merge pull request 'master' (#1) from grunfink/snac2:master into master
Reviewed-on: https://codeberg.org/louis77/snac2/pulls/1
Diffstat (limited to 'xs_unicode.h')
-rw-r--r--xs_unicode.h22
1 files changed, 11 insertions, 11 deletions
diff --git a/xs_unicode.h b/xs_unicode.h
index 47e1101..1799d89 100644
--- a/xs_unicode.h
+++ b/xs_unicode.h
@@ -6,7 +6,7 @@
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 int xs_is_utf8_cont_byte(char c);
9 unsigned int xs_utf8_dec(char **str); 9 unsigned int xs_utf8_dec(const 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); 11 int xs_is_surrogate(unsigned int cpoint);
12 unsigned int xs_surrogate_dec(unsigned int p1, unsigned int p2); 12 unsigned int xs_surrogate_dec(unsigned int p1, unsigned int p2);
@@ -27,8 +27,8 @@
27 27
28#ifdef XS_IMPLEMENTATION 28#ifdef XS_IMPLEMENTATION
29 29
30#ifndef countof 30#ifndef xs_countof
31#define countof(a) (sizeof((a)) / sizeof((*a))) 31#define xs_countof(a) (sizeof((a)) / sizeof((*a)))
32#endif 32#endif
33 33
34int _xs_utf8_enc(char buf[4], unsigned int cpoint) 34int _xs_utf8_enc(char buf[4], unsigned int cpoint)
@@ -66,10 +66,10 @@ int xs_is_utf8_cont_byte(char c)
66} 66}
67 67
68 68
69unsigned int xs_utf8_dec(char **str) 69unsigned int xs_utf8_dec(const char **str)
70/* decodes an utf-8 char inside str and updates the pointer */ 70/* decodes an utf-8 char inside str and updates the pointer */
71{ 71{
72 char *p = *str; 72 const char *p = *str;
73 unsigned int cpoint = 0; 73 unsigned int cpoint = 0;
74 unsigned char c = *p++; 74 unsigned char c = *p++;
75 int cb = 0; 75 int cb = 0;
@@ -125,7 +125,7 @@ int xs_unicode_width(unsigned int cpoint)
125/* returns the width in columns of a Unicode codepoint (somewhat simplified) */ 125/* returns the width in columns of a Unicode codepoint (somewhat simplified) */
126{ 126{
127 int b = 0; 127 int b = 0;
128 int t = countof(xs_unicode_width_table) / 3 - 1; 128 int t = xs_countof(xs_unicode_width_table) / 3 - 1;
129 129
130 while (t >= b) { 130 while (t >= b) {
131 int n = (b + t) / 2; 131 int n = (b + t) / 2;
@@ -193,7 +193,7 @@ unsigned int *_xs_unicode_upper_search(unsigned int cpoint)
193/* searches for an uppercase codepoint in the case fold table */ 193/* searches for an uppercase codepoint in the case fold table */
194{ 194{
195 int b = 0; 195 int b = 0;
196 int t = countof(xs_unicode_case_fold_table) / 2 + 1; 196 int t = xs_countof(xs_unicode_case_fold_table) / 2 + 1;
197 197
198 while (t >= b) { 198 while (t >= b) {
199 int n = (b + t) / 2; 199 int n = (b + t) / 2;
@@ -216,7 +216,7 @@ unsigned int *_xs_unicode_lower_search(unsigned int cpoint)
216/* searches for a lowercase codepoint in the case fold table */ 216/* searches for a lowercase codepoint in the case fold table */
217{ 217{
218 unsigned int *p = xs_unicode_case_fold_table; 218 unsigned int *p = xs_unicode_case_fold_table;
219 unsigned int *e = p + countof(xs_unicode_case_fold_table); 219 unsigned int *e = p + xs_countof(xs_unicode_case_fold_table);
220 220
221 while (p < e) { 221 while (p < e) {
222 if (cpoint == p[1]) 222 if (cpoint == p[1])
@@ -251,7 +251,7 @@ int xs_unicode_nfd(unsigned int cpoint, unsigned int *base, unsigned int *diac)
251/* applies unicode Normalization Form D */ 251/* applies unicode Normalization Form D */
252{ 252{
253 int b = 0; 253 int b = 0;
254 int t = countof(xs_unicode_nfd_table) / 3 - 1; 254 int t = xs_countof(xs_unicode_nfd_table) / 3 - 1;
255 255
256 while (t >= b) { 256 while (t >= b) {
257 int n = (b + t) / 2; 257 int n = (b + t) / 2;
@@ -279,7 +279,7 @@ int xs_unicode_nfc(unsigned int base, unsigned int diac, unsigned int *cpoint)
279/* applies unicode Normalization Form C */ 279/* applies unicode Normalization Form C */
280{ 280{
281 unsigned int *p = xs_unicode_nfd_table; 281 unsigned int *p = xs_unicode_nfd_table;
282 unsigned int *e = p + countof(xs_unicode_nfd_table); 282 unsigned int *e = p + xs_countof(xs_unicode_nfd_table);
283 283
284 while (p < e) { 284 while (p < e) {
285 if (p[1] == base && p[2] == diac) { 285 if (p[1] == base && p[2] == diac) {
@@ -298,7 +298,7 @@ int xs_unicode_is_alpha(unsigned int cpoint)
298/* checks if a codepoint is an alpha (i.e. a letter) */ 298/* checks if a codepoint is an alpha (i.e. a letter) */
299{ 299{
300 int b = 0; 300 int b = 0;
301 int t = countof(xs_unicode_alpha_table) / 2 - 1; 301 int t = xs_countof(xs_unicode_alpha_table) / 2 - 1;
302 302
303 while (t >= b) { 303 while (t >= b) {
304 int n = (b + t) / 2; 304 int n = (b + t) / 2;