Fix and improve comments.
[sliver-openvswitch.git] / lib / svec.c
index 078b107..de8d0f8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -59,6 +59,12 @@ svec_clear(struct svec *svec)
     svec->n = 0;
 }
 
+bool
+svec_is_empty(const struct svec *svec)
+{
+    return svec->n == 0;
+}
+
 void
 svec_add(struct svec *svec, const char *name)
 {
@@ -104,6 +110,16 @@ svec_append(struct svec *svec, const struct svec *other)
     }
 }
 
+void
+svec_move(struct svec *svec, struct svec *other)
+{
+    size_t i;
+    for (i = 0; i < other->n; i++) {
+        svec_add_nocopy(svec, other->names[i]);
+    }
+    other->n = 0;
+}
+
 void
 svec_terminate(struct svec *svec)
 {
@@ -366,6 +382,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)
 {