summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-06-16 14:46:17 +0200
committerThomas Haller <thaller@redhat.com>2015-07-02 15:50:03 +0200
commit885d187d23d44de0a3b8696d03a9e8fa2cc29f54 (patch)
tree39933b8128ebfd8039d542b98677f4ce354f7f90
parent69f2d22bfe355f89b6ce9622613ab0e9be7d1dd1 (diff)
downloadNetworkManager-885d187d23d44de0a3b8696d03a9e8fa2cc29f54.tar.gz
libnm: add _nm_utils_strv_cleanup() function
-rw-r--r--libnm-core/nm-core-internal.h5
-rw-r--r--libnm-core/nm-utils.c30
2 files changed, 35 insertions, 0 deletions
diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h
index f9ae42ecdd..d7cb47bf29 100644
--- a/libnm-core/nm-core-internal.h
+++ b/libnm-core/nm-core-internal.h
@@ -121,6 +121,11 @@ gboolean _nm_utils_string_in_list (const char *str,
gssize _nm_utils_strv_find_first (char **list, gssize len, const char *needle);
+char **_nm_utils_strv_cleanup (char **strv,
+ gboolean strip_whitespace,
+ gboolean skip_empty,
+ gboolean skip_repeated);
+
char ** _nm_utils_strsplit_set (const char *str,
const char *delimiters,
int max_tokens);
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c
index f9325e2a47..875882f132 100644
--- a/libnm-core/nm-utils.c
+++ b/libnm-core/nm-utils.c
@@ -483,6 +483,36 @@ _nm_utils_strv_find_first (char **list, gssize len, const char *needle)
return -1;
}
+char **
+_nm_utils_strv_cleanup (char **strv,
+ gboolean strip_whitespace,
+ gboolean skip_empty,
+ gboolean skip_repeated)
+{
+ guint i, j;
+
+ if (!strv || !*strv)
+ return strv;
+
+ if (strip_whitespace) {
+ for (i = 0; strv[i]; i++)
+ g_strstrip (strv[i]);
+ }
+ 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 (strv, j, strv[i]) >= 0))
+ g_free (strv[i]);
+ else
+ strv[j++] = strv[i];
+ }
+ strv[j] = NULL;
+ return strv;
+}
+
+
gboolean
_nm_utils_string_slist_validate (GSList *list, const char **valid_values)
{