shared: add nm_utils_strdict_clone() helper

This commit is contained in:
Thomas Haller 2020-11-07 19:18:39 +01:00
parent 571aeec933
commit 0cf4250021
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 20 additions and 0 deletions

View file

@ -434,6 +434,24 @@ nm_g_variant_singleton_u_0(void)
/*****************************************************************************/
GHashTable *
nm_utils_strdict_clone(GHashTable *src)
{
GHashTable * dst;
GHashTableIter iter;
const char * key;
const char * val;
if (!src)
return NULL;
dst = g_hash_table_new_full(nm_str_hash, g_str_equal, g_free, g_free);
g_hash_table_iter_init(&iter, src);
while (g_hash_table_iter_next(&iter, (gpointer *) &key, (gpointer *) &val))
g_hash_table_insert(dst, g_strdup(key), g_strdup(val));
return dst;
}
/* Convert a hash table with "char *" keys and values to an "a{ss}" GVariant.
* The keys will be sorted asciibetically.
* Returns a floating reference.

View file

@ -320,6 +320,8 @@ gboolean nm_utils_gbytes_equal_mem(GBytes *bytes, gconstpointer mem_data, gsize
GVariant *nm_utils_gbytes_to_variant_ay(GBytes *bytes);
GHashTable *nm_utils_strdict_clone(GHashTable *src);
GVariant *nm_utils_strdict_to_variant_ass(GHashTable *strdict);
GVariant *nm_utils_strdict_to_variant_asv(GHashTable *strdict);