From: Ben Pfaff <blp@nicira.com>
Date: Mon, 23 Nov 2009 19:09:38 +0000 (-0800)
Subject: svec: New function svec_split().
X-Git-Tag: v0.99.0~15
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=cfae8ec3e7ba9e02d4f994f77ef70435cd3575e5;p=sliver-openvswitch.git

svec: New function svec_split().

This is useful in an upcoming commit.
---

diff --git a/lib/svec.c b/lib/svec.c
index 078b10704..9d0f313d9 100644
--- a/lib/svec.c
+++ b/lib/svec.c
@@ -366,6 +366,22 @@ svec_join(const struct svec *svec,
     return ds_cstr(&ds);
 }
 
+/* Breaks 's' into tokens at any character in 'delimiters', and appends each
+ * token to 'svec'.  Empty tokens are not added. */
+void
+svec_split(struct svec *svec, const char *s_, const char *delimiters)
+{
+    char *s = xstrdup(s_);
+    char *save_ptr = NULL;
+    char *token;
+
+    for (token = strtok_r(s, delimiters, &save_ptr); token != NULL;
+         token = strtok_r(NULL, delimiters, &save_ptr)) {
+        svec_add(svec, token);
+    }
+    free(s);
+}
+
 const char *
 svec_back(const struct svec *svec)
 {
diff --git a/lib/svec.h b/lib/svec.h
index e1736bc6c..ac2266249 100644
--- a/lib/svec.h
+++ b/lib/svec.h
@@ -52,6 +52,7 @@ void svec_swap(struct svec *a, struct svec *b);
 void svec_print(const struct svec *svec, const char *title);
 void svec_parse_words(struct svec *svec, const char *words);
 bool svec_equal(const struct svec *, const struct svec *);
+void svec_split(struct svec *, const char *s, const char *delimiters);
 char *svec_join(const struct svec *,
                 const char *delimiter, const char *terminator);
 const char *svec_back(const struct svec *);