diff options
author | Nikias Bassen | 2014-03-19 02:26:09 +0100 |
---|---|---|
committer | Nikias Bassen | 2014-03-19 02:26:09 +0100 |
commit | f9299fa80a7530fea4b829ea851972a664edf1fe (patch) | |
tree | 94cf6141a7ef3c4661f05d33cb26e05d6e1b2410 /src/plist.c | |
parent | 6dcc8c48bb372ad372ffb1848bd24c6b416fd16e (diff) | |
download | libplist-f9299fa80a7530fea4b829ea851972a664edf1fe.tar.gz libplist-f9299fa80a7530fea4b829ea851972a664edf1fe.tar.bz2 |
plist_dict_set_item: insert key/value pair if key not already present
Diffstat (limited to 'src/plist.c')
-rw-r--r-- | src/plist.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/plist.c b/src/plist.c index e077ad9..f33de0a 100644 --- a/src/plist.c +++ b/src/plist.c @@ -405,17 +405,18 @@ plist_t plist_dict_get_item(plist_t node, const char* key) void plist_dict_set_item(plist_t node, const char* key, plist_t item) { - if (node && PLIST_DICT == plist_get_node_type(node)) - { + if (node && PLIST_DICT == plist_get_node_type(node)) { node_t* old_item = plist_dict_get_item(node, key); - if (old_item) - { + if (old_item) { int idx = plist_free_node(old_item); - if (idx < 0) { - node_attach(node, item); - } else { - node_insert(node, idx, item); - } + if (idx < 0) { + node_attach(node, item); + } else { + node_insert(node, idx, item); + } + } else { + node_attach(node, plist_new_key(key)); + node_attach(node, item); } } return; @@ -466,7 +467,7 @@ void plist_dict_merge(plist_t *target, plist_t source) if (plist_dict_get_item(*target, key) != NULL) plist_dict_remove_item(*target, key); - plist_dict_insert_item(*target, key, plist_copy(subnode)); + plist_dict_set_item(*target, key, plist_copy(subnode)); free(key); key = NULL; } while (1); |