From 39dcac2281970febcce36a0151796af2986388b3 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sat, 7 Nov 2026 09:12:48 +0300 Subject: publish --- src/sb.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/sb.h (limited to 'src/sb.h') diff --git a/src/sb.h b/src/sb.h new file mode 100644 index 0000000..070897b --- /dev/null +++ b/src/sb.h @@ -0,0 +1,34 @@ +// sb.h --- string builder +#ifndef INCLUDED_SB_H +#define INCLUDED_SB_H + +#include "utils.h" +#include "da.h" + +typedef struct sb { + char *items; + size_t count; + size_t capacity; +} *SB; + +#define SB_APPEND_BUF(SB, BUF, SIZE) DA_APPEND_MANY(SB, BUF, SIZE) + +#define SB_APPEND_CSTR(SB, CSTR) \ + ({ \ + const char *s = (CSTR); \ + size_t n = strlen (s); \ + DA_APPEND_MANY(SB, s, n); \ + }) + +#define SB_APPEND_CSTRS(SB, ...) sb_append_cstrs (&(SB), __VA_ARGS__, NULL) + +#define SB_APPEND_NULL(SB) DA_APPEND(SB, '\0') + +#define SB_RESET(SB) DA_RESET(SB) + +#define SB_FREE(SB) DA_FREE(SB) + +extern void sb_append_cstrs (SB sb, ...); +extern void sb_printf (SB sb, const char *format, ...); + +#endif -- cgit v1.3.1