diff options
Diffstat (limited to '')
| -rw-r--r-- | xs.h | 4 | ||||
| -rw-r--r-- | xs_json.h | 10 | ||||
| -rw-r--r-- | xs_mime.h | 22 | ||||
| -rw-r--r-- | xs_unicode.h | 16 | ||||
| -rw-r--r-- | xs_url.h | 2 | ||||
| -rw-r--r-- | xs_version.h | 2 |
6 files changed, 32 insertions, 24 deletions
| @@ -45,6 +45,10 @@ typedef char xs_data; | |||
| 45 | /* not really all, just very much */ | 45 | /* not really all, just very much */ |
| 46 | #define XS_ALL 0xfffffff | 46 | #define XS_ALL 0xfffffff |
| 47 | 47 | ||
| 48 | #ifndef xs_countof | ||
| 49 | #define xs_countof(a) (sizeof((a)) / sizeof((*a))) | ||
| 50 | #endif | ||
| 51 | |||
| 48 | void *xs_free(void *ptr); | 52 | void *xs_free(void *ptr); |
| 49 | void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func); | 53 | void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func); |
| 50 | #define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__, __FUNCTION__) | 54 | #define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__, __FUNCTION__) |
| @@ -328,7 +328,7 @@ static xs_val *_xs_json_load_lexer(FILE *f, js_type *t) | |||
| 328 | 328 | ||
| 329 | int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c) | 329 | int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c) |
| 330 | /* loads the next scalar value from the JSON stream */ | 330 | /* loads the next scalar value from the JSON stream */ |
| 331 | /* if the value ahead is complex, value is NULL and pt is filled */ | 331 | /* if the value ahead is compound, value is NULL and pt is set */ |
| 332 | { | 332 | { |
| 333 | js_type t; | 333 | js_type t; |
| 334 | 334 | ||
| @@ -348,7 +348,7 @@ int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c) | |||
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | if (*value == NULL) { | 350 | if (*value == NULL) { |
| 351 | /* possible complex type ahead */ | 351 | /* possible compound type ahead */ |
| 352 | if (t == JS_OBRACK) | 352 | if (t == JS_OBRACK) |
| 353 | *pt = XSTYPE_LIST; | 353 | *pt = XSTYPE_LIST; |
| 354 | else | 354 | else |
| @@ -365,7 +365,7 @@ int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c) | |||
| 365 | 365 | ||
| 366 | 366 | ||
| 367 | xs_list *xs_json_load_array(FILE *f) | 367 | xs_list *xs_json_load_array(FILE *f) |
| 368 | /* loads a JSON array (after the initial OBRACK) */ | 368 | /* loads a full JSON array (after the initial OBRACK) */ |
| 369 | { | 369 | { |
| 370 | xstype t; | 370 | xstype t; |
| 371 | xs_list *l = xs_list_new(); | 371 | xs_list *l = xs_list_new(); |
| @@ -406,7 +406,7 @@ xs_list *xs_json_load_array(FILE *f) | |||
| 406 | 406 | ||
| 407 | int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt, int *c) | 407 | int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt, int *c) |
| 408 | /* loads the next key and scalar value from the JSON stream */ | 408 | /* loads the next key and scalar value from the JSON stream */ |
| 409 | /* if the value ahead is complex, value is NULL and pt is filled */ | 409 | /* if the value ahead is compound, value is NULL and pt is set */ |
| 410 | { | 410 | { |
| 411 | js_type t; | 411 | js_type t; |
| 412 | 412 | ||
| @@ -453,7 +453,7 @@ int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt, | |||
| 453 | 453 | ||
| 454 | 454 | ||
| 455 | xs_dict *xs_json_load_object(FILE *f) | 455 | xs_dict *xs_json_load_object(FILE *f) |
| 456 | /* loads a JSON object (after the initial OCURLY) */ | 456 | /* loads a full JSON object (after the initial OCURLY) */ |
| 457 | { | 457 | { |
| 458 | xstype t; | 458 | xstype t; |
| 459 | xs_dict *d = xs_dict_new(); | 459 | xs_dict *d = xs_dict_new(); |
| @@ -55,19 +55,23 @@ const char *xs_mime_by_ext(const char *file) | |||
| 55 | const char *ext = strrchr(file, '.'); | 55 | const char *ext = strrchr(file, '.'); |
| 56 | 56 | ||
| 57 | if (ext) { | 57 | if (ext) { |
| 58 | const char **p = xs_mime_types; | 58 | xs *uext = xs_tolower_i(xs_dup(ext + 1)); |
| 59 | xs *uext = xs_tolower_i(xs_dup(ext + 1)); | 59 | int b = 0; |
| 60 | int t = xs_countof(xs_mime_types) / 2 - 2; | ||
| 60 | 61 | ||
| 61 | while (*p) { | 62 | while (t >= b) { |
| 62 | int c; | 63 | int n = (b + t) / 2; |
| 64 | const char *p = xs_mime_types[n * 2]; | ||
| 63 | 65 | ||
| 64 | if ((c = strcmp(*p, uext)) == 0) | 66 | int c = strcmp(uext, p); |
| 65 | return p[1]; | 67 | |
| 68 | if (c < 0) | ||
| 69 | t = n - 1; | ||
| 66 | else | 70 | else |
| 67 | if (c > 0) | 71 | if (c > 0) |
| 68 | break; | 72 | b = n + 1; |
| 69 | 73 | else | |
| 70 | p += 2; | 74 | return xs_mime_types[(n * 2) + 1]; |
| 71 | } | 75 | } |
| 72 | } | 76 | } |
| 73 | 77 | ||
diff --git a/xs_unicode.h b/xs_unicode.h index 47e1101..6654da4 100644 --- a/xs_unicode.h +++ b/xs_unicode.h | |||
| @@ -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 | ||
| 34 | int _xs_utf8_enc(char buf[4], unsigned int cpoint) | 34 | int _xs_utf8_enc(char buf[4], unsigned int cpoint) |
| @@ -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; |
| @@ -56,7 +56,7 @@ xs_dict *xs_url_vars(const char *str) | |||
| 56 | 56 | ||
| 57 | l = args; | 57 | l = args; |
| 58 | while (xs_list_iter(&l, &v)) { | 58 | while (xs_list_iter(&l, &v)) { |
| 59 | xs *kv = xs_split_n(v, "=", 2); | 59 | xs *kv = xs_split_n(v, "=", 1); |
| 60 | 60 | ||
| 61 | if (xs_list_len(kv) == 2) { | 61 | if (xs_list_len(kv) == 2) { |
| 62 | const char *key = xs_list_get(kv, 0); | 62 | const char *key = xs_list_get(kv, 0); |
diff --git a/xs_version.h b/xs_version.h index ef52120..f655735 100644 --- a/xs_version.h +++ b/xs_version.h | |||
| @@ -1 +1 @@ | |||
| /* 0df383371d207b0adfda40912ee54b37e5b01152 2024-03-15T03:45:39+01:00 */ | /* f712d1336ef427c3b56305364b2687578537543f 2024-04-14T19:11:53+02:00 */ | ||