From ec673f15786acbcedb724089c3a99420e83eea07 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 20 Jan 2009 13:34:02 -0800 Subject: [PATCH] New function svec_join(). --- lib/svec.c | 16 ++++++++++++++++ lib/svec.h | 1 + 2 files changed, 17 insertions(+) diff --git a/lib/svec.c b/lib/svec.c index 728866b6..7f7e7594 100644 --- a/lib/svec.c +++ b/lib/svec.c @@ -321,3 +321,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); +} diff --git a/lib/svec.h b/lib/svec.h index 084d2e85..68d361c4 100644 --- a/lib/svec.h +++ b/lib/svec.h @@ -65,5 +65,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 */ -- 2.30.2