diff options
author | Ted Gould <ted@gould.cx> | 2010-06-28 17:24:09 -0500 |
---|---|---|
committer | Ted Gould <ted@gould.cx> | 2010-06-28 17:24:09 -0500 |
commit | 3bbd2b821624a706b94a297e7e46442b9ae227f9 (patch) | |
tree | ea851645b174c3dc363781c910cbe5614c18f8c0 | |
parent | ccd36f867b28766e708ab7bdbbd36fda3492a8fd (diff) | |
download | libdbusmenu-3bbd2b821624a706b94a297e7e46442b9ae227f9.tar.gz libdbusmenu-3bbd2b821624a706b94a297e7e46442b9ae227f9.tar.bz2 libdbusmenu-3bbd2b821624a706b94a297e7e46442b9ae227f9.zip |
Okay, now we've got some basic code for dealing with value arrays
-rw-r--r-- | tests/json-loader.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/json-loader.c b/tests/json-loader.c index 64e1579..2f27bff 100644 --- a/tests/json-loader.c +++ b/tests/json-loader.c @@ -21,6 +21,37 @@ node2value (JsonNode * node) JsonNode * first = json_array_get_element(array, 0); if (JSON_NODE_TYPE(first) == JSON_NODE_VALUE) { + GValue subvalue = {0}; + json_node_get_value(first, &subvalue); + + if (G_VALUE_TYPE(&subvalue) == G_TYPE_STRING) { + GArray * garray = g_array_sized_new(TRUE, TRUE, sizeof(gchar *), json_array_get_length(array)); + g_value_init(value, G_TYPE_STRV); + g_value_take_boxed(value, garray->data); + + int i; + for (i = 0; i < json_array_get_length(array); i++) { + const gchar * str = json_node_get_string(first); + gchar * dupstr = g_strdup(str); + g_array_append_val(garray, dupstr); + } + + g_array_free(garray, FALSE); + } else { + GValueArray * varray = g_value_array_new(json_array_get_length(array)); + g_value_init(value, G_TYPE_VALUE_ARRAY); + g_value_take_boxed(value, varray); + + g_value_array_append(varray, &subvalue); + g_value_unset(&subvalue); + + int i; + for (i = 1; i < json_array_get_length(array); i++) { + json_node_get_value(first, &subvalue); + g_value_array_append(varray, &subvalue); + g_value_unset(&subvalue); + } + } } else { GValue * subvalue = node2value(first); |