diff options
author | Emmanuele Bassi <ebassi@openedhand.com> | 2007-11-21 20:41:42 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@openedhand.com> | 2007-11-21 20:41:42 +0000 |
commit | cf2eceeb69ccbda4f2ff583ee7869c7fd3cda603 (patch) | |
tree | cb53f0d635d9556b35f2fc66fd43020110baeaa8 /json-glib/json-array.c | |
parent | 5a4a8761af0562fbee8e1a56ce1771a20c1ad8e3 (diff) | |
download | json-glib-cf2eceeb69ccbda4f2ff583ee7869c7fd3cda603.tar.gz |
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.
Diffstat (limited to 'json-glib/json-array.c')
-rw-r--r-- | json-glib/json-array.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 @@ -180,6 +180,35 @@ json_array_get_elements (JsonArray *array) } /** + * 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 * @index_: the index of the element to retrieve |