summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-04-14 19:26:49 +0200
committerdefault <nobody@localhost>2024-04-14 19:26:49 +0200
commit0275658a3602f74035ff776dac8d8f64b9a2794f (patch)
treed9489684e46d7cd0d5bd8347a880316abe22f48f
parent81cf1e21a646568323681df2763e66f933bee48f (diff)
Backport from xs.
-rw-r--r--xs.h4
-rw-r--r--xs_json.h10
-rw-r--r--xs_mime.h22
-rw-r--r--xs_unicode.h16
-rw-r--r--xs_url.h2
-rw-r--r--xs_version.h2
6 files changed, 32 insertions, 24 deletions
diff --git a/xs.h b/xs.h
index d2de44a..bab315a 100644
--- a/xs.h
+++ b/xs.h
@@ -45,6 +45,10 @@ typedef char xs_data;
/* not really all, just very much */
#define XS_ALL 0xfffffff
+#ifndef xs_countof
+#define xs_countof(a) (sizeof((a)) / sizeof((*a)))
+#endif
+
void *xs_free(void *ptr);
void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func);
#define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__, __FUNCTION__)
diff --git a/xs_json.h b/xs_json.h
index 1494fe8..6706d7e 100644
--- a/xs_json.h
+++ b/xs_json.h
@@ -328,7 +328,7 @@ static xs_val *_xs_json_load_lexer(FILE *f, js_type *t)
int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
/* loads the next scalar value from the JSON stream */
-/* if the value ahead is complex, value is NULL and pt is filled */
+/* if the value ahead is compound, value is NULL and pt is set */
{
js_type t;
@@ -348,7 +348,7 @@ int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
}
if (*value == NULL) {
- /* possible complex type ahead */
+ /* possible compound type ahead */
if (t == JS_OBRACK)
*pt = XSTYPE_LIST;
else
@@ -365,7 +365,7 @@ int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
xs_list *xs_json_load_array(FILE *f)
-/* loads a JSON array (after the initial OBRACK) */
+/* loads a full JSON array (after the initial OBRACK) */
{
xstype t;
xs_list *l = xs_list_new();
@@ -406,7 +406,7 @@ xs_list *xs_json_load_array(FILE *f)
int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt, int *c)
/* loads the next key and scalar value from the JSON stream */
-/* if the value ahead is complex, value is NULL and pt is filled */
+/* if the value ahead is compound, value is NULL and pt is set */
{
js_type t;
@@ -453,7 +453,7 @@ int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt,
xs_dict *xs_json_load_object(FILE *f)
-/* loads a JSON object (after the initial OCURLY) */
+/* loads a full JSON object (after the initial OCURLY) */
{
xstype t;
xs_dict *d = xs_dict_new();
diff --git a/xs_mime.h b/xs_mime.h
index 84af49c..853b092 100644
--- a/xs_mime.h
+++ b/xs_mime.h
@@ -55,19 +55,23 @@ const char *xs_mime_by_ext(const char *file)
const char *ext = strrchr(file, '.');
if (ext) {
- const char **p = xs_mime_types;
- xs *uext = xs_tolower_i(xs_dup(ext + 1));
+ xs *uext = xs_tolower_i(xs_dup(ext + 1));
+ int b = 0;
+ int t = xs_countof(xs_mime_types) / 2 - 2;
- while (*p) {
- int c;
+ while (t >= b) {
+ int n = (b + t) / 2;
+ const char *p = xs_mime_types[n * 2];
- if ((c = strcmp(*p, uext)) == 0)
- return p[1];
+ int c = strcmp(uext, p);
+
+ if (c < 0)
+ t = n - 1;
else
if (c > 0)
- break;
-
- p += 2;
+ b = n + 1;
+ else
+ return xs_mime_types[(n * 2) + 1];
}
}
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 @@
#ifdef XS_IMPLEMENTATION
-#ifndef countof
-#define countof(a) (sizeof((a)) / sizeof((*a)))
+#ifndef xs_countof
+#define xs_countof(a) (sizeof((a)) / sizeof((*a)))
#endif
int _xs_utf8_enc(char buf[4], unsigned int cpoint)
@@ -125,7 +125,7 @@ int xs_unicode_width(unsigned int cpoint)
/* returns the width in columns of a Unicode codepoint (somewhat simplified) */
{
int b = 0;
- int t = countof(xs_unicode_width_table) / 3 - 1;
+ int t = xs_countof(xs_unicode_width_table) / 3 - 1;
while (t >= b) {
int n = (b + t) / 2;
@@ -193,7 +193,7 @@ unsigned int *_xs_unicode_upper_search(unsigned int cpoint)
/* searches for an uppercase codepoint in the case fold table */
{
int b = 0;
- int t = countof(xs_unicode_case_fold_table) / 2 + 1;
+ int t = xs_countof(xs_unicode_case_fold_table) / 2 + 1;
while (t >= b) {
int n = (b + t) / 2;
@@ -216,7 +216,7 @@ unsigned int *_xs_unicode_lower_search(unsigned int cpoint)
/* searches for a lowercase codepoint in the case fold table */
{
unsigned int *p = xs_unicode_case_fold_table;
- unsigned int *e = p + countof(xs_unicode_case_fold_table);
+ unsigned int *e = p + xs_countof(xs_unicode_case_fold_table);
while (p < e) {
if (cpoint == p[1])
@@ -251,7 +251,7 @@ int xs_unicode_nfd(unsigned int cpoint, unsigned int *base, unsigned int *diac)
/* applies unicode Normalization Form D */
{
int b = 0;
- int t = countof(xs_unicode_nfd_table) / 3 - 1;
+ int t = xs_countof(xs_unicode_nfd_table) / 3 - 1;
while (t >= b) {
int n = (b + t) / 2;
@@ -279,7 +279,7 @@ int xs_unicode_nfc(unsigned int base, unsigned int diac, unsigned int *cpoint)
/* applies unicode Normalization Form C */
{
unsigned int *p = xs_unicode_nfd_table;
- unsigned int *e = p + countof(xs_unicode_nfd_table);
+ unsigned int *e = p + xs_countof(xs_unicode_nfd_table);
while (p < e) {
if (p[1] == base && p[2] == diac) {
@@ -298,7 +298,7 @@ int xs_unicode_is_alpha(unsigned int cpoint)
/* checks if a codepoint is an alpha (i.e. a letter) */
{
int b = 0;
- int t = countof(xs_unicode_alpha_table) / 2 - 1;
+ int t = xs_countof(xs_unicode_alpha_table) / 2 - 1;
while (t >= b) {
int n = (b + t) / 2;
diff --git a/xs_url.h b/xs_url.h
index f335709..6c9c8b5 100644
--- a/xs_url.h
+++ b/xs_url.h
@@ -56,7 +56,7 @@ xs_dict *xs_url_vars(const char *str)
l = args;
while (xs_list_iter(&l, &v)) {
- xs *kv = xs_split_n(v, "=", 2);
+ xs *kv = xs_split_n(v, "=", 1);
if (xs_list_len(kv) == 2) {
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 */