New function svec_join().
authorBen Pfaff <blp@nicira.com>
Tue, 20 Jan 2009 21:34:02 +0000 (13:34 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 21 Jan 2009 00:45:22 +0000 (16:45 -0800)
lib/svec.c
lib/svec.h

index f006639..b568f67 100644 (file)
@@ -293,3 +293,19 @@ svec_equal(const struct svec *a, const struct svec *b)
     }
     return true;
 }
+
+char *
+svec_join(const struct svec *svec, const char *delimiter)
+{
+    struct ds ds;
+    size_t i;
+
+    ds_init(&ds);
+    for (i = 0; i < svec->n; i++) {
+        if (i) {
+            ds_put_cstr(&ds, delimiter);
+        }
+        ds_put_cstr(&ds, svec->names[i]);
+    }
+    return ds_cstr(&ds);
+}
index 2ee275d..3362c00 100644 (file)
@@ -62,5 +62,6 @@ 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 *);
+char *svec_join(const struct svec *, const char *delimiter);
 
 #endif /* svec.h */