diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2009-05-17 19:44:41 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2009-05-17 19:44:41 +0100 |
commit | 930fdf4c4dff1f5310a946c2a9f5b6860f7c8ba8 (patch) | |
tree | ea8fbd8f41fce7bbb41069817630d5af90ed349d /json-glib/json-array.c | |
parent | 3057a1722e27a13b39ddec4754fb6abda1aea199 (diff) | |
download | json-glib-930fdf4c4dff1f5310a946c2a9f5b6860f7c8ba8.tar.gz |
Add JsonArray iteration function
Similarly to commit 3057a172 for JsonObject, the newly added
json_array_foreach_element() iterates over a JSON array data
type.
Diffstat (limited to 'json-glib/json-array.c')
-rw-r--r-- | json-glib/json-array.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/json-glib/json-array.c b/json-glib/json-array.c index 13ac3b8..301e050 100644 --- a/json-glib/json-array.c +++ b/json-glib/json-array.c @@ -667,3 +667,38 @@ json_array_remove_element (JsonArray *array, json_node_free (g_ptr_array_remove_index (array->elements, index_)); } + +/** + * json_array_foreach_element: + * @array: a #JsonArray + * @func: the function to be called on each element + * @data: data to be passed to the function + * + * Iterates over all elements of @array and calls @func on + * each one of them. + * + * It is safe to change the value of a #JsonNode of the @array + * from within the iterator @func, but it is not safe to add or + * remove elements from the @array. + * + * Since: 0.8 + */ +void +json_array_foreach_element (JsonArray *array, + JsonArrayForeach func, + gpointer data) +{ + gint i; + + g_return_if_fail (array != NULL); + g_return_if_fail (func != NULL); + + for (i = 0; i < array->elements->len; i++) + { + JsonNode *element_node; + + element_node = g_ptr_array_index (array->elements, i); + + (* func) (array, i, element_node, data); + } +} |