summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorPaul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>2019-02-25 23:16:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-02-28 23:03:46 (GMT)
commite71c4a88f65ca1d325f52b19bf79c3660eab50f7 (patch)
tree2ab09d955ecaee487f6912d7b38990c4d7261c93 /strbuf.c
parentf5116f43f69720059375059311485d99c462551b (diff)
downloadgit-e71c4a88f65ca1d325f52b19bf79c3660eab50f7.zip
git-e71c4a88f65ca1d325f52b19bf79c3660eab50f7.tar.gz
git-e71c4a88f65ca1d325f52b19bf79c3660eab50f7.tar.bz2
strbuf.c: add `strbuf_join_argv()`
Implement `strbuf_join_argv()` to join arguments into a strbuf. Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/strbuf.c b/strbuf.c
index f6a6cf7..82e90f1 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -268,6 +268,21 @@ void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
strbuf_setlen(sb, sb->len + sb2->len);
}
+const char *strbuf_join_argv(struct strbuf *buf,
+ int argc, const char **argv, char delim)
+{
+ if (!argc)
+ return buf->buf;
+
+ strbuf_addstr(buf, *argv);
+ while (--argc) {
+ strbuf_addch(buf, delim);
+ strbuf_addstr(buf, *(++argv));
+ }
+
+ return buf->buf;
+}
+
void strbuf_addchars(struct strbuf *sb, int c, size_t n)
{
strbuf_grow(sb, n);