aboutsummaryrefslogtreecommitdiff
path: root/lib/svec.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2009-11-23 11:09:38 -0800
committerBen Pfaff <blp@nicira.com>2009-11-23 15:58:48 -0800
commitcfae8ec3e7ba9e02d4f994f77ef70435cd3575e5 (patch)
tree8b9a7897edee4a99156578c403aaecbe4daa0ab6 /lib/svec.c
parentefacbce62f4ca3baf305441641ee35aa5b657442 (diff)
svec: New function svec_split().
This is useful in an upcoming commit.
Diffstat (limited to 'lib/svec.c')
-rw-r--r--lib/svec.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/svec.c b/lib/svec.c
index 078b1070..9d0f313d 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)
{