Improve cursor position after :substitute command
[vis.git] / buffer.h
blob037055bb786dbbcd412153a3e58004d320f1acf8
1 #ifndef BUFFER_H
2 #define BUFFER_H
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include "text.h"
8 /* a dynamically growing buffer storing arbitrary data, used for registers/macros */
9 typedef struct {
10 char *data; /* NULL if empty */
11 size_t len; /* current length of data */
12 size_t size; /* maximal capacity of the buffer */
13 } 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 /* replace buffer content with given data, growing the buffer if needed */
26 bool buffer_put(Buffer*, const void *data, size_t len);
27 /* same but with NUL-terminated data */
28 bool buffer_put0(Buffer*, const char *data);
29 /* insert arbitrary data of length len at pos (in [0, buf->len]) */
30 bool buffer_insert(Buffer*, size_t pos, const void *data, size_t len);
31 /* insert NUL-terminate data at pos (in [0, buf->len]) */
32 bool buffer_insert0(Buffer*, size_t pos, const char *data);
33 /* append futher content to the end of the buffer data */
34 bool buffer_append(Buffer*, const void *data, size_t len);
35 /* append NUl-terminated data */
36 bool buffer_append0(Buffer*, const char *data);
37 /* insert new data at the start of the buffer */
38 bool buffer_prepend(Buffer*, const void *data, size_t len);
39 /* prepend NUL-terminated data */
40 bool buffer_prepend0(Buffer*, const char *data);
42 #endif