From 930fdf4c4dff1f5310a946c2a9f5b6860f7c8ba8 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Sun, 17 May 2009 19:44:41 +0100 Subject: Add JsonArray iteration function Similarly to commit 3057a172 for JsonObject, the newly added json_array_foreach_element() iterates over a JSON array data type. --- json-glib/json-array.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'json-glib/json-array.c') 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); + } +} -- cgit v1.2.1