* [PATCH v2 7/9] json: add json_iter_get_container
@ 2022-01-06 19:50 James Prestwood
0 siblings, 0 replies; only message in thread
From: James Prestwood @ 2022-01-06 19:50 UTC (permalink / raw)
To: iwd
[-- Attachment #1: Type: text/plain, Size: 1387 bytes --]
This allows getting an iterator for a container nested inside
an array.
---
src/json.c | 14 ++++++++++++++
src/json.h | 2 ++
2 files changed, 16 insertions(+)
diff --git a/src/json.c b/src/json.c
index aec5fe5c..6e40629d 100644
--- a/src/json.c
+++ b/src/json.c
@@ -383,6 +383,20 @@ bool json_iter_get_null(struct json_iter *iter)
return false;
}
+bool json_iter_get_container(struct json_iter *iter,
+ struct json_iter *container)
+{
+ struct json_contents *c = iter->contents;
+ jsmntok_t *t = c->tokens + iter->current;
+
+ if (t->type != JSMN_OBJECT && t->type != JSMN_ARRAY)
+ return false;
+
+ iter_recurse(iter, t, container);
+
+ return true;
+}
+
enum json_type json_iter_get_type(struct json_iter *iter)
{
struct json_contents *c = iter->contents;
diff --git a/src/json.h b/src/json.h
index 458deb93..518d778c 100644
--- a/src/json.h
+++ b/src/json.h
@@ -93,6 +93,8 @@ bool json_iter_get_int(struct json_iter *iter, int *i);
bool json_iter_get_uint(struct json_iter *iter, unsigned int *i);
bool json_iter_get_boolean(struct json_iter *iter, bool *b);
bool json_iter_get_null(struct json_iter *iter);
+bool json_iter_get_container(struct json_iter *iter,
+ struct json_iter *container);
enum json_type json_iter_get_type(struct json_iter *iter);
bool json_iter_next(struct json_iter *iter);
--
2.31.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2022-01-06 19:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-06 19:50 [PATCH v2 7/9] json: add json_iter_get_container James Prestwood
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox