shared: add nm_utils_hash_keys_to_array() helper
This commit is contained in:
@@ -1149,31 +1149,34 @@ nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len)
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char **
|
gpointer *
|
||||||
nm_utils_strdict_get_keys (const GHashTable *hash,
|
nm_utils_hash_keys_to_array (GHashTable *hash,
|
||||||
gboolean sorted,
|
GCompareDataFunc compare_func,
|
||||||
guint *out_length)
|
gpointer user_data,
|
||||||
|
guint *out_len)
|
||||||
{
|
{
|
||||||
const char **names;
|
guint len;
|
||||||
guint length;
|
gpointer *keys;
|
||||||
|
|
||||||
|
/* by convention, we never return an empty array. In that
|
||||||
|
* case, always %NULL. */
|
||||||
if ( !hash
|
if ( !hash
|
||||||
|| !g_hash_table_size ((GHashTable *) hash)) {
|
|| g_hash_table_size (hash) == 0) {
|
||||||
NM_SET_OUT (out_length, 0);
|
NM_SET_OUT (out_len, 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
names = (const char **) g_hash_table_get_keys_as_array ((GHashTable *) hash, &length);
|
keys = g_hash_table_get_keys_as_array (hash, &len);
|
||||||
if ( sorted
|
if ( len > 1
|
||||||
&& length > 1) {
|
&& compare_func) {
|
||||||
g_qsort_with_data (names,
|
g_qsort_with_data (keys,
|
||||||
length,
|
len,
|
||||||
sizeof (char *),
|
sizeof (gpointer),
|
||||||
nm_strcmp_p_with_data,
|
compare_func,
|
||||||
NULL);
|
user_data);
|
||||||
}
|
}
|
||||||
NM_SET_OUT (out_length, length);
|
NM_SET_OUT (out_len, len);
|
||||||
return names;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
char **
|
char **
|
||||||
|
@@ -460,9 +460,21 @@ typedef struct {
|
|||||||
|
|
||||||
NMUtilsNamedValue *nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len);
|
NMUtilsNamedValue *nm_utils_named_values_from_str_dict (GHashTable *hash, guint *out_len);
|
||||||
|
|
||||||
const char **nm_utils_strdict_get_keys (const GHashTable *hash,
|
gpointer *nm_utils_hash_keys_to_array (GHashTable *hash,
|
||||||
gboolean sorted,
|
GCompareDataFunc compare_func,
|
||||||
guint *out_length);
|
gpointer user_data,
|
||||||
|
guint *out_len);
|
||||||
|
|
||||||
|
static inline const char **
|
||||||
|
nm_utils_strdict_get_keys (const GHashTable *hash,
|
||||||
|
gboolean sorted,
|
||||||
|
guint *out_length)
|
||||||
|
{
|
||||||
|
return (const char **) nm_utils_hash_keys_to_array ((GHashTable *) hash,
|
||||||
|
sorted ? nm_strcmp_p_with_data : NULL,
|
||||||
|
NULL,
|
||||||
|
out_length);
|
||||||
|
}
|
||||||
|
|
||||||
char **nm_utils_strv_make_deep_copied (const char **strv);
|
char **nm_utils_strv_make_deep_copied (const char **strv);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user