gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
src
text.c
Go to the documentation of this file.
1
#include "
gwion_util.h
"
2
3
ANN
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
12
ANN
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
}
ANN
#define ANN
Definition
defs.h:19
m_uint
uintptr_t m_uint
Definition
gwcommon.h:11
m_str
char * m_str
Definition
gwcommon.h:14
str
char ** str
Definition
gwion_print.h:2
gwion_util.h
meta header (use this to include the whole library)
mp_realloc
void * mp_realloc(MemPool mp, void *ptr, const m_uint curr, const m_uint next)
Definition
mpool.c:148
GwText_
mp_allocted text
Definition
gwion_text.h:8
GwText_::len
size_t len
Definition
gwion_text.h:11
GwText_::cap
size_t cap
Definition
gwion_text.h:10
GwText_::str
m_str str
Definition
gwion_text.h:9
GwText_::mp
MemPool mp
Definition
gwion_text.h:12
text_add
ANN void text_add(GwText *text, const char *str)
append to text
Definition
text.c:12
text_grow
static ANN m_str text_grow(GwText *text, const size_t sz)
Definition
text.c:3
Generated by
1.10.0