aboutsummaryrefslogtreecommitdiff
path: root/src/sb.h
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-07 06:12:48 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-07 06:21:22 +0000
commit39dcac2281970febcce36a0151796af2986388b3 (patch)
tree7339e54dc942a3ab0d9ba9daae56a2801c1917e9 /src/sb.h
downloadcoursework-39dcac2281970febcce36a0151796af2986388b3.tar.gz
publishHEADmaster
Diffstat (limited to 'src/sb.h')
-rw-r--r--src/sb.h34
1 files changed, 34 insertions, 0 deletions
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 @@
1// sb.h --- string builder
2#ifndef INCLUDED_SB_H
3#define INCLUDED_SB_H
4
5#include "utils.h"
6#include "da.h"
7
8typedef struct sb {
9 char *items;
10 size_t count;
11 size_t capacity;
12} *SB;
13
14#define SB_APPEND_BUF(SB, BUF, SIZE) DA_APPEND_MANY(SB, BUF, SIZE)
15
16#define SB_APPEND_CSTR(SB, CSTR) \
17 ({ \
18 const char *s = (CSTR); \
19 size_t n = strlen (s); \
20 DA_APPEND_MANY(SB, s, n); \
21 })
22
23#define SB_APPEND_CSTRS(SB, ...) sb_append_cstrs (&(SB), __VA_ARGS__, NULL)
24
25#define SB_APPEND_NULL(SB) DA_APPEND(SB, '\0')
26
27#define SB_RESET(SB) DA_RESET(SB)
28
29#define SB_FREE(SB) DA_FREE(SB)
30
31extern void sb_append_cstrs (SB sb, ...);
32extern void sb_printf (SB sb, const char *format, ...);
33
34#endif