From ba56172222658da23322e863ca1f45666b9af9f1 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 4 Apr 2009 18:04:37 +0200 Subject: [PATCH] Add a func to remove a string obj from an array. --HG-- extra : convert_revision : 2de9ea16361286a17e93e9fb65a93bd28e7688db --- include/plist.h | 3 +++ lib/plist.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/plist.h b/include/plist.h index 0f23c73ac15..30b7491b5aa 100644 --- a/include/plist.h +++ b/include/plist.h @@ -107,4 +107,7 @@ xbps_remove_pkg_dict_from_file(const char *, const char *); bool xbps_remove_pkg_from_dict(prop_dictionary_t, const char *, const char *); +int +xbps_remove_string_from_array(prop_array_t, const char *); + #endif /* !_XBPS_PLIST_H_ */ diff --git a/lib/plist.c b/lib/plist.c index 0c3ed0d6ff3..3f91b2305bf 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -237,6 +237,39 @@ xbps_get_array_iter_from_dict(prop_dictionary_t dict, const char *key) return prop_array_iterator(array); } +int +xbps_remove_string_from_array(prop_array_t array, const char *str) +{ + prop_object_t obj; + prop_object_iterator_t iter; + size_t idx = 0; + bool found = false; + + assert(array != NULL); + assert(str != NULL); + + iter = prop_array_iterator(array); + if (iter == NULL) + return ENOMEM; + + while ((obj = prop_object_iterator_next(iter)) != NULL) { + if (prop_object_type(obj) != PROP_TYPE_STRING) + continue; + if (prop_string_equals_cstring(obj, str)) { + found = true; + break; + } + idx++; + } + prop_object_iterator_release(iter); + if (found == false) + return ENOENT; + + prop_array_remove(array, idx); + + return 0; +} + bool xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key, const char *pkgname)