You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2016/08/01 11:40:13 UTC
[4/5] lucy-clownfish git commit: Implement CFCJson_find_hash_elem
Implement CFCJson_find_hash_elem
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/bff120c5
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/bff120c5
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/bff120c5
Branch: refs/heads/master
Commit: bff120c521ce1f2ce09a438069a55cb077124efa
Parents: 8ac4a06
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Mar 19 19:58:50 2016 +0100
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Fri Jul 22 16:06:48 2016 +0200
----------------------------------------------------------------------
compiler/src/CFCJson.c | 15 +++++++++++++++
compiler/src/CFCJson.h | 3 +++
2 files changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bff120c5/compiler/src/CFCJson.c
----------------------------------------------------------------------
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 @@ CFCJson_get_children(CFCJson *self) {
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;
+}
+
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/bff120c5/compiler/src/CFCJson.h
----------------------------------------------------------------------
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_get_num_children(CFCJson *self);
CFCJson**
CFCJson_get_children(CFCJson *self);
+CFCJson*
+CFCJson_find_hash_elem(CFCJson *self, const char *key);
+
#ifdef __cplusplus
}
#endif