From 9a513348057d8c62a65e08214206dae77b766b83 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Sun, 10 Nov 2024 00:53:34 -0500 Subject: add str_fmt() --- str.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'str.c') diff --git a/str.c b/str.c index 1c09f11..8d1806e 100644 --- a/str.c +++ b/str.c @@ -1,4 +1,5 @@ #include +#include #include #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); +} -- cgit 1.4.1-2-gfad0