-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonutil.c
More file actions
38 lines (34 loc) · 1.05 KB
/
Copy pathjsonutil.c
File metadata and controls
38 lines (34 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifdef __ORCAC__
#pragma noroot
#endif
#include <string.h>
#include "jsonutil.h"
json_value *findEntryInObject(json_value *obj, json_char *name, json_type type) {
if (obj == NULL || obj->type != json_object)
return NULL;
json_object_entry *entry = obj->u.object.values;
for (unsigned int i = 0; i < obj->u.object.length; i++,entry++) {
if (entry->name_length != strlen(name)) {
continue;
}
if (memcmp(name, entry->name, entry->name_length) == 0) {
if (entry->value->type == type)
return entry->value;
else
return NULL;
}
}
return NULL;
}
boolean processArray(json_value *arr, json_type member_type, boolean (*f)(json_value*)) {
if (arr == NULL || arr->type != json_array)
return false;
for (unsigned int i = 0; i < arr->u.array.length; i++) {
json_value *v = arr->u.array.values[i];
if (v->type != member_type)
continue;
if (f(v) == false)
return false;
}
return true;
}