DiskBrowser/jsonutil.c
Stephen Heumann 999b6130a4 Rearrange/refactor DiskBrowser code into smaller, more focused files.
There are only a few minor code changes, and nothing that should have an effect on functionality. This is basically just rearranging the code.
2019-04-18 13:24:43 -05:00

39 lines
1.0 KiB
C

#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;
}