1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#ifndef STRING_H
#define STRING_H
#include <stddef.h>
#define SV(sp, str) sv_create(sp, str, sizeof(str));
struct StringView {
char *buf;
size_t len;
};
#define STRING_CONST {NULL, 0}
struct StringPool {
void *mem;
size_t size;
size_t offset;
};
#define STRINGPOOL_CONST {NULL, 0, 0}
typedef struct StringView StringView;
typedef struct StringPool StringPool;
void sp_init(StringPool *sp, size_t len);
void* sp_reserve(StringPool *sp, size_t len);
StringView sv_create(StringPool *sp, char *str, size_t len);
StringView sv_concat_ss(StringPool *sp, StringView a, StringView b);
StringView sv_concat_ss_n(StringPool *sp, int n, ...);
StringView sv_sizet_to_string(StringPool *sp, size_t s);
void sv_printf_cs(char *fmt, ...);
#endif
|