From ee7748172e4ef716559109ef0dbb139cfb40f08a 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 f0066392d..b568f6779 100644 --- a/lib/svec.c +++ b/lib/svec.c @@ -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); +} diff --git a/lib/svec.h b/lib/svec.h index 2ee275dec..3362c00b5 100644 --- a/lib/svec.h +++ b/lib/svec.h @@ -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 */ -- 2.43.0