gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Functions
text.c File Reference
#include "gwion_util.h"

Go to the source code of this file.

Functions

static ANN m_str text_grow (GwText *text, const size_t sz)
 
ANN void text_add (GwText *text, const char *str)
 append to text
 

Function Documentation

◆ text_add()

ANN void text_add ( GwText * text,
const char * str )

append to text

Definition at line 12 of file text.c.

12 {
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}
char ** str
Definition gwion_print.h:2
size_t len
Definition gwion_text.h:11
static ANN m_str text_grow(GwText *text, const size_t sz)
Definition text.c:3

◆ text_grow()

static ANN m_str text_grow ( GwText * text,
const size_t sz )
inlinestatic

Definition at line 3 of file text.c.

3 {
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}
uintptr_t m_uint
Definition gwcommon.h:11
char * m_str
Definition gwcommon.h:14
void * mp_realloc(MemPool mp, void *ptr, const m_uint curr, const m_uint next)
Definition mpool.c:148
size_t cap
Definition gwion_text.h:10
m_str str
Definition gwion_text.h:9
MemPool mp
Definition gwion_text.h:12