8 /* a dynamically growing buffer storing arbitrary data, used for registers/macros */
10 char *data
; /* NULL if empty */
11 size_t len
; /* current length of data */
12 size_t size
; /* maximal capacity of the buffer */
15 /* initalize a (stack allocated) Buffer instance */
16 void buffer_init(Buffer
*);
17 /* release/free all data stored in this buffer, reset size to zero */
18 void buffer_release(Buffer
*);
19 /* set buffer size to zero, keep allocated memory */
20 void buffer_clear(Buffer
*);
21 /* reserve space to store at least size bytes in this buffer.*/
22 bool buffer_grow(Buffer
*, size_t size
);
23 /* truncate buffer, but keep associated memory region for further data */
24 void buffer_truncate(Buffer
*);
25 /* if buffer is not empty, make sure it is NUL terminated */
26 bool buffer_terminate(Buffer
*);
27 /* replace buffer content with given data, growing the buffer if needed */
28 bool buffer_put(Buffer
*, const void *data
, size_t len
);
29 /* same but with NUL-terminated data */
30 bool buffer_put0(Buffer
*, const char *data
);
31 /* remove len bytes from the buffer starting at pos */
32 bool buffer_remove(Buffer
*, size_t pos
, size_t len
);
33 /* insert arbitrary data of length len at pos (in [0, buf->len]) */
34 bool buffer_insert(Buffer
*, size_t pos
, const void *data
, size_t len
);
35 /* insert NUL-terminate data at pos (in [0, buf->len]) */
36 bool buffer_insert0(Buffer
*, size_t pos
, const char *data
);
37 /* append futher content to the end of the buffer data */
38 bool buffer_append(Buffer
*, const void *data
, size_t len
);
39 /* append NUl-terminated data */
40 bool buffer_append0(Buffer
*, const char *data
);
41 /* insert new data at the start of the buffer */
42 bool buffer_prepend(Buffer
*, const void *data
, size_t len
);
43 /* prepend NUL-terminated data */
44 bool buffer_prepend0(Buffer
*, const char *data
);
46 bool buffer_printf(Buffer
*, const char *fmt
, ...);
47 bool buffer_vprintf(Buffer
*, const char *fmt
, va_list);
48 /* return length of a buffer without trailing NUL byte */
49 size_t buffer_length0(Buffer
*);
50 /* return length of a buffer including possible NUL byte */
51 size_t buffer_length(Buffer
*);
52 /* pointer to buffer data, guaranteed to return a NUL terminated
53 * string even if buffer is empty */
54 const char *buffer_content0(Buffer
*);
55 /* pointer to buffer data, might be NULL if empty, might not be NUL terminated */
56 const char *buffer_content(Buffer
*);