quote: implement sq_quotef()

Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jacob Keller committed Feb 29, 2016 at 14:58 UTC e70986d72515b7601aea7d8d86a9d3bed53866f3
2 files changed +16
quote.c
+13
@@ -43,6 +43,19 @@ void sq_quote_buf(struct strbuf *dst, const char *src)
43 free(to_free);
44 }
45
46 +void sq_quotef(struct strbuf *dst, const char *fmt, ...)
47 +{
48 + struct strbuf src = STRBUF_INIT;
49 +
50 + va_list ap;
51 + va_start(ap, fmt);
52 + strbuf_vaddf(&src, fmt, ap);
53 + va_end(ap);
54 +
55 + sq_quote_buf(dst, src.buf);
56 + strbuf_release(&src);
57 +}
58 +
59 void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)
60 {
61 int i;
quote.h
+3
@@ -25,10 +25,13 @@ struct strbuf;
25 * sq_quote_buf() writes to an existing buffer of specified size; it
26 * will return the number of characters that would have been written
27 * excluding the final null regardless of the buffer size.
28 + *
29 + * sq_quotef() quotes the entire formatted string as a single result.
30 */
31
32 extern void sq_quote_buf(struct strbuf *, const char *src);
33 extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
34 +extern void sq_quotef(struct strbuf *, const char *fmt, ...);
35
36 /* This unwraps what sq_quote() produces in place, but returns
37 * NULL if the input does not look like what sq_quote would have