summary refs log tree commit diff
path: root/str.c
diff options
context:
space:
mode:
authorWormHeamer2024-11-10 00:53:34 -0500
committerWormHeamer2024-11-10 00:57:53 -0500
commit9a513348057d8c62a65e08214206dae77b766b83 (patch)
treebfe0f4c23b72bda67f3db15ceca83a207fc97747 /str.c
parent3f54d883edc90d0e6419210eff6be8125ba89daf (diff)
add str_fmt()
Diffstat (limited to 'str.c')
-rw-r--r--str.c25
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);
+}