gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
text.c
Go to the documentation of this file.
1#include "gwion_util.h"
2
3ANN static inline m_str text_grow(GwText *text, const size_t sz) {
4 if (text->cap <= sz) {
5 const m_uint cap = text->cap;
6 while (text->cap <= sz) text->cap <<= 1;
7 text->str = (m_str)mp_realloc(text->mp, text->str, cap, text->cap);
8 }
9 return text->str + text->len;
10}
11
12ANN void text_add(GwText *text, const char *str) {
13 const size_t sz = strlen(str);
14 const size_t len = sz + text->len + 1;
15 strcpy(text_grow(text, len), str);
16 text->len += sz;
17}
#define ANN
Definition defs.h:19
uintptr_t m_uint
Definition gwcommon.h:11
char * m_str
Definition gwcommon.h:14
char ** str
Definition gwion_print.h:2
meta header (use this to include the whole library)
void * mp_realloc(MemPool mp, void *ptr, const m_uint curr, const m_uint next)
Definition mpool.c:148
mp_allocted text
Definition gwion_text.h:8
size_t len
Definition gwion_text.h:11
size_t cap
Definition gwion_text.h:10
m_str str
Definition gwion_text.h:9
MemPool mp
Definition gwion_text.h:12
ANN void text_add(GwText *text, const char *str)
append to text
Definition text.c:12
static ANN m_str text_grow(GwText *text, const size_t sz)
Definition text.c:3