Add a func to remove a string obj from an array.

--HG--
extra : convert_revision : 2de9ea16361286a17e93e9fb65a93bd28e7688db
This commit is contained in:
Juan RP 2009-04-04 18:04:37 +02:00
parent 44926cd53c
commit ba56172222
2 changed files with 36 additions and 0 deletions

View file

@ -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_ */

View file

@ -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)