properties: add function to copy list of keys

This commit is contained in:
Wim Taymans 2019-08-16 21:54:49 +02:00
parent 774e11bc10
commit 32ce5c4deb
2 changed files with 26 additions and 0 deletions

View file

@ -203,6 +203,29 @@ struct pw_properties *pw_properties_copy(const struct pw_properties *properties)
return pw_properties_new_dict(&properties->dict);
}
/** Copy multiple keys from one property to another
*
* \param src properties to copy from
* \param dst properties to copy to
* \param keys a NULL terminated list of keys to copy
* \return the number of keys changed in \a dest
*
* \memberof pw_properties
*/
SPA_EXPORT
int pw_properties_copy_keys(const struct pw_properties *src,
struct pw_properties *dst, const char *keys[])
{
int i, changed = 0;
const char *str;
for (i = 0; keys[i]; i++) {
if ((str = pw_properties_get(src, keys[i])) != NULL)
changed += pw_properties_set(dst, keys[i], str);
}
return changed;
}
/** Clear a properties object
*
* \param properties properties to clear

View file

@ -57,6 +57,9 @@ pw_properties_new_string(const char *args);
struct pw_properties *
pw_properties_copy(const struct pw_properties *properties);
int pw_properties_copy_keys(const struct pw_properties *src,
struct pw_properties *dst, const char *keys[]);
int
pw_properties_update(struct pw_properties *oldprops,
const struct spa_dict *dict);