Implement CFCJson_find_hash_elem
diff --git a/compiler/src/CFCJson.c b/compiler/src/CFCJson.c
index 262b943..1f3a396 100644
--- a/compiler/src/CFCJson.c
+++ b/compiler/src/CFCJson.c
@@ -277,3 +277,18 @@
return self->kids;
}
+CFCJson*
+CFCJson_find_hash_elem(CFCJson *self, const char *key) {
+ if (self->type != CFCJSON_HASH) {
+ CFCUtil_die("Not a JSON hash");
+ }
+
+ for (int i = 0; self->kids[i]; i += 2) {
+ if (strcmp(self->kids[i]->string, key) == 0) {
+ return self->kids[i+1];
+ }
+ }
+
+ return NULL;
+}
+
diff --git a/compiler/src/CFCJson.h b/compiler/src/CFCJson.h
index 97d7081..052a1b8 100644
--- a/compiler/src/CFCJson.h
+++ b/compiler/src/CFCJson.h
@@ -49,6 +49,9 @@
CFCJson**
CFCJson_get_children(CFCJson *self);
+CFCJson*
+CFCJson_find_hash_elem(CFCJson *self, const char *key);
+
#ifdef __cplusplus
}
#endif