glib-aux: add _nm_utils_strv_cleanup_const() helper

This commit is contained in:
Thomas Haller 2021-07-28 23:25:28 +02:00
parent e2c5634ecd
commit f0ec3d5a56
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 28 additions and 1 deletions

View file

@ -2382,13 +2382,37 @@ nm_strv_is_same_unordered(const char *const *strv1,
return TRUE;
}
const char **
_nm_utils_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated)
{
gsize i;
gsize j;
if (!strv || !*strv)
return strv;
if (!skip_empty && !skip_repeated)
return strv;
j = 0;
for (i = 0; strv[i]; i++) {
if ((skip_empty && !*strv[i])
|| (skip_repeated && nm_utils_strv_find_first((char **) strv, j, strv[i]) >= 0))
continue;
strv[j++] = strv[i];
}
strv[j] = NULL;
return strv;
}
char **
_nm_utils_strv_cleanup(char ** strv,
gboolean strip_whitespace,
gboolean skip_empty,
gboolean skip_repeated)
{
guint i, j;
gsize i;
gsize j;
if (!strv || !*strv)
return strv;

View file

@ -741,6 +741,9 @@ gssize nm_utils_strv_find_first(char **list, gssize len, const char *needle);
gboolean nm_strv_has_duplicate(const char *const *list, gssize len, gboolean is_sorted);
const char **
_nm_utils_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated);
char **_nm_utils_strv_cleanup(char ** strv,
gboolean strip_whitespace,
gboolean skip_empty,