$darkmode
Herb C Reference
buffer.h
Go to the documentation of this file.
1 #ifndef HERB_BUFFER_H
2 #define HERB_BUFFER_H
3 
4 #include <stdbool.h>
5 #include <stdlib.h>
6 
7 typedef struct BUFFER_STRUCT {
8  char* value;
9  size_t length;
10  size_t capacity;
12 
13 bool buffer_init(buffer_T* buffer);
14 buffer_T buffer_new(void);
15 
16 bool buffer_increase_capacity(buffer_T* buffer, size_t additional_capacity);
17 bool buffer_has_capacity(buffer_T* buffer, size_t required_length);
18 bool buffer_expand_capacity(buffer_T* buffer);
19 bool buffer_expand_if_needed(buffer_T* buffer, size_t required_length);
20 bool buffer_resize(buffer_T* buffer, size_t new_capacity);
21 
22 void buffer_append(buffer_T* buffer, const char* text);
23 void buffer_append_with_length(buffer_T* buffer, const char* text, size_t length);
24 void buffer_append_char(buffer_T* buffer, char character);
25 void buffer_append_repeated(buffer_T* buffer, char character, size_t length);
26 void buffer_append_whitespace(buffer_T* buffer, size_t length);
27 void buffer_prepend(buffer_T* buffer, const char* text);
28 void buffer_concat(buffer_T* destination, buffer_T* source);
29 
30 char* buffer_value(const buffer_T* buffer);
31 
32 size_t buffer_length(const buffer_T* buffer);
33 size_t buffer_capacity(const buffer_T* buffer);
34 size_t buffer_sizeof(void);
35 
36 void buffer_clear(buffer_T* buffer);
37 void buffer_free(buffer_T* buffer);
38 
39 #endif
size_t buffer_length(const buffer_T *buffer)
Definition: buffer.c:35
size_t buffer_sizeof(void)
Definition: buffer.c:43
size_t buffer_capacity(const buffer_T *buffer)
Definition: buffer.c:39
void buffer_append_whitespace(buffer_T *buffer, size_t length)
Definition: buffer.c:188
bool buffer_init(buffer_T *buffer)
Definition: buffer.c:10
bool buffer_expand_if_needed(buffer_T *buffer, size_t required_length)
Expands the capacity of the buffer if needed to accommodate additional content.
Definition: buffer.c:114
struct BUFFER_STRUCT buffer_T
void buffer_concat(buffer_T *destination, buffer_T *source)
Definition: buffer.c:206
void buffer_clear(buffer_T *buffer)
Definition: buffer.c:220
void buffer_append_repeated(buffer_T *buffer, char character, size_t length)
Definition: buffer.c:174
buffer_T buffer_new(void)
Definition: buffer.c:25
char * buffer_value(const buffer_T *buffer)
Definition: buffer.c:31
void buffer_free(buffer_T *buffer)
Definition: buffer.c:225
bool buffer_resize(buffer_T *buffer, size_t new_capacity)
Resizes the capacity of the buffer to the specified new capacity.
Definition: buffer.c:74
void buffer_append(buffer_T *buffer, const char *text)
Appends a null-terminated string to the buffer.
Definition: buffer.c:130
void buffer_prepend(buffer_T *buffer, const char *text)
Definition: buffer.c:192
void buffer_append_with_length(buffer_T *buffer, const char *text, size_t length)
Appends a string of specified length to the buffer.
Definition: buffer.c:155
bool buffer_has_capacity(buffer_T *buffer, size_t required_length)
Definition: buffer.c:216
bool buffer_increase_capacity(buffer_T *buffer, size_t additional_capacity)
Increases the capacity of the buffer if needed to accommodate additional content.
Definition: buffer.c:56
void buffer_append_char(buffer_T *buffer, char character)
Definition: buffer.c:165
bool buffer_expand_capacity(buffer_T *buffer)
Expands the capacity of the buffer by doubling its current capacity.
Definition: buffer.c:101
Definition: buffer.h:7
size_t length
Definition: buffer.h:9
size_t capacity
Definition: buffer.h:10
char * value
Definition: buffer.h:8