From cf2eceeb69ccbda4f2ff583ee7869c7fd3cda603 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 21 Nov 2007 20:41:42 +0000 Subject: Add API to retrieve copies of the nodes inside objects and arrays Getting copies of the nodes might work better for high level languages binding the JSON-GLib API, because they can manage the lifetime of the returned values using their own rules. --- json-glib/json-array.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'json-glib/json-array.c') diff --git a/json-glib/json-array.c b/json-glib/json-array.c index 530674a..d699bed 100644 --- a/json-glib/json-array.c +++ b/json-glib/json-array.c @@ -179,6 +179,35 @@ json_array_get_elements (JsonArray *array) return g_list_reverse (retval); } +/** + * json_array_dup_element: + * @array: a #JsonArray + * @index_: the index of the element to retrieve + * + * Retrieves a copy of the #JsonNode containing the value of the + * element at @index_ inside a #JsonArray + * + * Return value: a copy of the #JsonNode at the requested index. + * Use json_node_free() when done. + * + * Since: 0.6 + */ +JsonNode * +json_array_dup_element (JsonArray *array, + guint index_) +{ + JsonNode *retval; + + g_return_val_if_fail (array != NULL, NULL); + g_return_val_if_fail (index_ < array->elements->len, NULL); + + retval = json_array_get_element (array, index_); + if (!retval) + return NULL; + + return json_node_copy (retval); +} + /** * json_array_get_element: * @array: a #JsonArray -- cgit v1.2.1