summaryrefslogtreecommitdiff
path: root/xs_json.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_json.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_json.h')
-rw-r--r--xs_json.h23
1 files changed, 11 insertions, 12 deletions
diff --git a/xs_json.h b/xs_json.h
index 1494fe8..b65e825 100644
--- a/xs_json.h
+++ b/xs_json.h
@@ -71,12 +71,12 @@ static void _xs_json_indent(int level, int indent, FILE *f)
71} 71}
72 72
73 73
74static void _xs_json_dump(const xs_val *s_data, int level, int indent, FILE *f) 74static void _xs_json_dump(const xs_val *data, int level, int indent, FILE *f)
75/* dumps partial data as JSON */ 75/* dumps partial data as JSON */
76{ 76{
77 int c = 0; 77 int c = 0;
78 xs_val *v; 78 int ct = 0;
79 xs_val *data = (xs_val *)s_data; 79 const xs_val *v;
80 80
81 switch (xs_type(data)) { 81 switch (xs_type(data)) {
82 case XSTYPE_NULL: 82 case XSTYPE_NULL:
@@ -98,7 +98,7 @@ static void _xs_json_dump(const xs_val *s_data, int level, int indent, FILE *f)
98 case XSTYPE_LIST: 98 case XSTYPE_LIST:
99 fputc('[', f); 99 fputc('[', f);
100 100
101 while (xs_list_iter(&data, &v)) { 101 while (xs_list_next(data, &v, &ct)) {
102 if (c != 0) 102 if (c != 0)
103 fputc(',', f); 103 fputc(',', f);
104 104
@@ -116,10 +116,9 @@ static void _xs_json_dump(const xs_val *s_data, int level, int indent, FILE *f)
116 case XSTYPE_DICT: 116 case XSTYPE_DICT:
117 fputc('{', f); 117 fputc('{', f);
118 118
119 xs_str *k; 119 const xs_str *k;
120 int ct = 0;
121 120
122 while (xs_dict_next(s_data, &k, &v, &ct)) { 121 while (xs_dict_next(data, &k, &v, &ct)) {
123 if (c != 0) 122 if (c != 0)
124 fputc(',', f); 123 fputc(',', f);
125 124
@@ -328,7 +327,7 @@ static xs_val *_xs_json_load_lexer(FILE *f, js_type *t)
328 327
329int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c) 328int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
330/* loads the next scalar value from the JSON stream */ 329/* loads the next scalar value from the JSON stream */
331/* if the value ahead is complex, value is NULL and pt is filled */ 330/* if the value ahead is compound, value is NULL and pt is set */
332{ 331{
333 js_type t; 332 js_type t;
334 333
@@ -348,7 +347,7 @@ int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
348 } 347 }
349 348
350 if (*value == NULL) { 349 if (*value == NULL) {
351 /* possible complex type ahead */ 350 /* possible compound type ahead */
352 if (t == JS_OBRACK) 351 if (t == JS_OBRACK)
353 *pt = XSTYPE_LIST; 352 *pt = XSTYPE_LIST;
354 else 353 else
@@ -365,7 +364,7 @@ int xs_json_load_array_iter(FILE *f, xs_val **value, xstype *pt, int *c)
365 364
366 365
367xs_list *xs_json_load_array(FILE *f) 366xs_list *xs_json_load_array(FILE *f)
368/* loads a JSON array (after the initial OBRACK) */ 367/* loads a full JSON array (after the initial OBRACK) */
369{ 368{
370 xstype t; 369 xstype t;
371 xs_list *l = xs_list_new(); 370 xs_list *l = xs_list_new();
@@ -406,7 +405,7 @@ xs_list *xs_json_load_array(FILE *f)
406 405
407int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt, int *c) 406int 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 */ 407/* 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 */ 408/* if the value ahead is compound, value is NULL and pt is set */
410{ 409{
411 js_type t; 410 js_type t;
412 411
@@ -453,7 +452,7 @@ int xs_json_load_object_iter(FILE *f, xs_str **key, xs_val **value, xstype *pt,
453 452
454 453
455xs_dict *xs_json_load_object(FILE *f) 454xs_dict *xs_json_load_object(FILE *f)
456/* loads a JSON object (after the initial OCURLY) */ 455/* loads a full JSON object (after the initial OCURLY) */
457{ 456{
458 xstype t; 457 xstype t;
459 xs_dict *d = xs_dict_new(); 458 xs_dict *d = xs_dict_new();