diff options
Diffstat (limited to 'str.c')
-rw-r--r-- | str.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/str.c b/str.c index 1c09f11..8d1806e 100644 --- a/str.c +++ b/str.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <stdarg.h> #include <string.h> #include "str.h" #include "err.h" @@ -67,3 +68,27 @@ char strv_next(strv_t *s) { return 0; } } + +void str_fmt(str_t *b, const char *fmt, ...) { + va_list ap; + char c; + b->sz = 0; + va_start(ap, fmt); + while ((c = *fmt++)) { + if (c == '%' && *fmt) { + switch ((c = *fmt++)) { + case 'c': + str_catc(b, va_arg(ap, int)); + break; + case 's': + str_cat(b, va_arg(ap, strv_t)); + break; + default: + str_catc(b, c); + } + } else { + str_catc(b, c); + } + } + va_end(ap); +} |