Commit fe7b4641 authored by Thomas Haller's avatar Thomas Haller

shared: add nm_utils_strdict_get_keys() helper

At various places we get the (string) keys of a GHashTable.
Add a helper function that does that, including an argument
for optional sorting.

The helper function is there to get reduce code duplication.
parent 0735b35d
......@@ -1148,3 +1148,30 @@ nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len)
NM_SET_OUT (out_len, len);
return values;
}
const char **
nm_utils_strdict_get_keys (const GHashTable *hash,
gboolean sorted,
guint *out_length)
{
const char **names;
guint length;
if ( !hash
|| !g_hash_table_size ((GHashTable *) hash)) {
NM_SET_OUT (out_length, 0);
return NULL;
}
names = (const char **) g_hash_table_get_keys_as_array ((GHashTable *) hash, &length);
if ( sorted
&& length > 1) {
g_qsort_with_data (names,
length,
sizeof (char *),
nm_strcmp_p_with_data,
NULL);
}
NM_SET_OUT (out_length, length);
return names;
}
......@@ -443,6 +443,10 @@ typedef struct {
NMUtilsNamedValue *nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len);
const char **nm_utils_strdict_get_keys (const GHashTable *hash,
gboolean sorted,
guint *out_length);
/*****************************************************************************/
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment