diff options
| author | 2026-11-07 06:12:48 +0000 | |
|---|---|---|
| committer | 2026-11-07 06:21:22 +0000 | |
| commit | 39dcac2281970febcce36a0151796af2986388b3 (patch) | |
| tree | 7339e54dc942a3ab0d9ba9daae56a2801c1917e9 /src/sb.h | |
| download | coursework-39dcac2281970febcce36a0151796af2986388b3.tar.gz | |
Diffstat (limited to 'src/sb.h')
| -rw-r--r-- | src/sb.h | 34 |
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 | |||
| 8 | typedef 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 | |||
| 31 | extern void sb_append_cstrs (SB sb, ...); | ||
| 32 | extern void sb_printf (SB sb, const char *format, ...); | ||
| 33 | |||
| 34 | #endif | ||
