shared: add nm_utils_g_slist_strlist_cmp() util

Usually we avoid GSList, because I think it's not a great data type.
Anyway, our match-specs are just a GSList of strings, so we need some
API to handle them.
This commit is contained in:
Thomas Haller 2019-06-13 18:13:23 +02:00
parent 3d0dba20b5
commit 1cc4a8b6a9
2 changed files with 21 additions and 0 deletions

View file

@ -2709,6 +2709,25 @@ nm_utils_g_slist_find_str (const GSList *list,
return NULL;
}
/**
* nm_utils_g_slist_strlist_cmp:
* @a: the left #GSList of strings
* @b: the right #GSList of strings to compare.
*
* Compares two string lists. The data elements are compared with
* strcmp(), alloing %NULL elements.
*
* Returns: 0, 1, or -1, depending on how the lists compare.
*/
int
nm_utils_g_slist_strlist_cmp (const GSList *a, const GSList *b)
{
for (; a && b; a = a->next, b = b->next)
NM_CMP_DIRECT_STRCMP0 (a->data, b->data);
NM_CMP_SELF (a, b);
return 0;
}
/*****************************************************************************/
gpointer

View file

@ -981,6 +981,8 @@ nm_utils_strv_make_deep_copied_nonnull (const char **strv)
GSList *nm_utils_g_slist_find_str (const GSList *list,
const char *needle);
int nm_utils_g_slist_strlist_cmp (const GSList *a, const GSList *b);
/*****************************************************************************/
gssize nm_utils_ptrarray_find_binary_search (gconstpointer *list,