Split CE code into multiple files
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m38s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m38s
This commit is contained in:
24
ce/strbuf.c
Normal file
24
ce/strbuf.c
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "strbuf.h"
|
||||
#include "arena_alloc.h"
|
||||
#include <arena.h>
|
||||
#include <stddef.h>
|
||||
|
||||
void strbuf_append (struct strbuf* strbuf, char c) {
|
||||
if (strbuf->items == NULL) {
|
||||
strbuf->capacity = 256;
|
||||
strbuf->count = 0;
|
||||
strbuf->items = arena_malloc (&arena, strbuf->capacity);
|
||||
} else {
|
||||
if (strbuf->count == strbuf->capacity) {
|
||||
size_t prev_capacity = strbuf->capacity;
|
||||
strbuf->capacity *= 2;
|
||||
strbuf->items = arena_realloc (&arena, strbuf->items, prev_capacity, strbuf->capacity);
|
||||
}
|
||||
}
|
||||
strbuf->items[strbuf->count++] = c;
|
||||
}
|
||||
|
||||
void strbuf_append_str (struct strbuf* strbuf, const char* s) {
|
||||
while (*s)
|
||||
strbuf_append (strbuf, *s++);
|
||||
}
|
||||
Reference in New Issue
Block a user