From 0c6ef834b242fae356fe27e907f9e8723cceda9d Mon Sep 17 00:00:00 2001 From: George Kiagiadakis <george.kiagiadakis@collabora.com> Date: Thu, 12 Sep 2019 16:05:40 +0300 Subject: [PATCH] lib: properties: add wp_properties_copy_keys A method to copy specific keys from one properties set to another --- lib/wp/properties.c | 26 ++++++++++++++++++++++++++ lib/wp/properties.h | 5 +++++ 2 files changed, 31 insertions(+) diff --git a/lib/wp/properties.c b/lib/wp/properties.c index b8d78346..e06b69fc 100644 --- a/lib/wp/properties.c +++ b/lib/wp/properties.c @@ -178,6 +178,32 @@ wp_properties_update_from_dict (WpProperties * self, return pw_properties_update (self->props, dict); } +gint +wp_properties_copy_keys (WpProperties * src, WpProperties * dst, + const gchar *key1, ...) +{ + gint ret; + va_list args; + va_start (args, key1); + ret = wp_properties_copy_keys_valist (src, dst, key1, args); + va_end (args); + return ret; +} + +gint +wp_properties_copy_keys_valist (WpProperties * src, WpProperties * dst, + const gchar *key1, va_list args) +{ + gint changed = 0; + const gchar *value; + + for (; key1; key1 = va_arg (args, const gchar *)) { + if ((value = wp_properties_get (src, key1)) != NULL) + changed += wp_properties_set (dst, key1, value); + } + return changed; +} + const gchar * wp_properties_get (WpProperties * self, const gchar * key) { diff --git a/lib/wp/properties.h b/lib/wp/properties.h index 3479f36a..553f937a 100644 --- a/lib/wp/properties.h +++ b/lib/wp/properties.h @@ -41,6 +41,11 @@ void wp_properties_unref (WpProperties * self); gint wp_properties_update_from_dict (WpProperties * self, const struct spa_dict * dict); +gint wp_properties_copy_keys (WpProperties * src, WpProperties * dst, + const gchar *key1, ...) G_GNUC_NULL_TERMINATED; +gint wp_properties_copy_keys_valist (WpProperties * src, WpProperties * dst, + const gchar *key1, va_list args); + const gchar * wp_properties_get (WpProperties * self, const gchar * key); gint wp_properties_set (WpProperties * self, const gchar * key, -- GitLab