diff options
author | Nikias Bassen | 2013-12-13 00:32:06 +0100 |
---|---|---|
committer | Nikias Bassen | 2013-12-13 00:32:06 +0100 |
commit | 3b7647499474619b3e24bf01105b6b037887a0ed (patch) | |
tree | 743215893ce32c6d535f0dc143cb3e9f4060a378 /src | |
parent | 8f644ca58ea2174241a3a3ddac943efdf353642c (diff) | |
download | libplist-3b7647499474619b3e24bf01105b6b037887a0ed.tar.gz libplist-3b7647499474619b3e24bf01105b6b037887a0ed.tar.bz2 |
add new plist_dict_merge() function
Diffstat (limited to 'src')
-rw-r--r-- | src/plist.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/plist.c b/src/plist.c index dcaf601..e077ad9 100644 --- a/src/plist.c +++ b/src/plist.c @@ -446,6 +446,33 @@ void plist_dict_remove_item(plist_t node, const char* key) return; } +void plist_dict_merge(plist_t *target, plist_t source) +{ + if (!target || !*target || (plist_get_node_type(*target) != PLIST_DICT) || !source || (plist_get_node_type(source) != PLIST_DICT)) + return; + + char* key = NULL; + plist_dict_iter it = NULL; + plist_t subnode = NULL; + plist_dict_new_iter(source, &it); + if (!it) + return; + + do { + plist_dict_next_item(source, it, &key, &subnode); + if (!key) + break; + + if (plist_dict_get_item(*target, key) != NULL) + plist_dict_remove_item(*target, key); + + plist_dict_insert_item(*target, key, plist_copy(subnode)); + free(key); + key = NULL; + } while (1); + free(it); +} + plist_t plist_access_pathv(plist_t plist, uint32_t length, va_list v) { plist_t current = plist; |