Adding upstream version 6.02~pre8+dfsg.
[syslinux-debian/hramrach.git] / com32 / gpllib / zzjson / zzjson_query.c
blob35ba7b793cc53e9dfce3896a483468f1cf1f6281
1 /* JSON query
2 * ZZJSON - Copyright (C) 2008 by Ivo van Poorten
3 * License: GNU Lesser General Public License version 2.1
4 */
6 #include "zzjson.h"
7 #include <string.h>
8 #include <stdarg.h>
10 ZZJSON *zzjson_object_find_label(ZZJSON *zzjson, char *label) {
11 if (zzjson->type != ZZJSON_OBJECT) return NULL;
13 while (zzjson) {
14 char *string = zzjson->value.object.label;
16 if (zzjson->type != ZZJSON_OBJECT) return NULL;
17 if (!string) return NULL;
19 if (!strcmp(string, label))
20 return zzjson->value.object.val;
21 zzjson = zzjson->next;
23 return NULL;
26 ZZJSON *zzjson_object_find_labels(ZZJSON *zzjson, ...) {
27 va_list ap;
28 char *lbl;
30 va_start(ap, zzjson);
31 lbl = va_arg(ap, char *);
32 while (lbl) {
33 zzjson = zzjson_object_find_label(zzjson, lbl);
34 if (!zzjson) break;
35 lbl = va_arg(ap, char *);
37 va_end(ap);
39 return zzjson;
42 unsigned int zzjson_object_count(ZZJSON *zzjson) {
43 unsigned int count = 1;
45 if (zzjson->type != ZZJSON_OBJECT) return 0;
46 if (!zzjson->value.object.label) return 0; /* empty { } */
48 while ((zzjson = zzjson->next)) count++;
50 return count;
53 unsigned int zzjson_array_count(ZZJSON *zzjson) {
54 unsigned int count = 1;
56 if (zzjson->type != ZZJSON_ARRAY) return 0;
57 if (!zzjson->value.array.val) return 0; /* empty [ ] */
59 while ((zzjson = zzjson->next)) count++;
61 return count;