summaryrefslogtreecommitdiffstats
path: root/jv.h
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2012-12-31 23:27:00 +0000
committerStephen Dolan <mu@netsoc.tcd.ie>2012-12-31 23:27:00 +0000
commitfb84541e1124565ee7af32cd842771cf81326dc7 (patch)
treefe664aae7589a2acd60f8c49c1c932123cee5120 /jv.h
parent38fe6fc0cbf23c3bb97b10529cda119cb4418245 (diff)
Clean up jv_object_foreach and add jv_array_foreach
Diffstat (limited to 'jv.h')
-rw-r--r--jv.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/jv.h b/jv.h
index 12e7c790..c3bff367 100644
--- a/jv.h
+++ b/jv.h
@@ -72,7 +72,13 @@ jv jv_array_set(jv, int, jv);
jv jv_array_append(jv, jv);
jv jv_array_concat(jv, jv);
jv jv_array_slice(jv, int, int);
-
+#define jv_array_foreach(a, i, x) \
+ for (int jv_len__ = jv_array_length(jv_copy(a)), i=0, jv_j__ = 1; \
+ jv_j__; jv_j__ = 0) \
+ for (jv x; \
+ i < jv_len__ ? \
+ (x = jv_array_get(jv_copy(a), i), 1) : 0; \
+ i++)
jv jv_string(const char*);
jv jv_string_sized(const char*, int);
@@ -96,10 +102,15 @@ int jv_object_iter_next(jv, int);
int jv_object_iter_valid(jv, int);
jv jv_object_iter_key(jv, int);
jv jv_object_iter_value(jv, int);
-#define jv_object_foreach(i,t) \
- for (int i = jv_object_iter(t); \
- jv_object_iter_valid(t, i); \
- i = jv_object_iter_next(t, i)) \
+#define jv_object_foreach(t, k, v) \
+ for (int jv_i__ = jv_object_iter(t), jv_j__ = 1; jv_j__; jv_j__ = 0) \
+ for (jv k, v; \
+ jv_object_iter_valid((t), jv_i__) ? \
+ (k = jv_object_iter_key(t, jv_i__), \
+ v = jv_object_iter_value(t, jv_i__), \
+ 1) \
+ : 0; \
+ jv_i__ = jv_object_iter_next(t, jv_i__)) \