gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
gwion_text.h
Go to the documentation of this file.
1
4#ifndef __GWTEXT
5#define __GWTEXT
6
8typedef struct GwText_ {
10 size_t cap;
11 size_t len;
14
16ANN void text_add(GwText *, const char *);
17
18ANN static inline void text_init(GwText *text, MemPool mp) {
19 text->mp = mp;
20 text->str = (m_str)mp_malloc2(mp, 64);
21 text->len = 0;
22 text->cap = 64;
23}
24
26ANN static inline void text_release(GwText *text) {
27 if (text->str) {
28 mp_free2(text->mp, text->cap, text->str);
29 text->str = NULL;
30 text->cap = text->len = 0;
31 }
32}
33
34ANN static inline GwText *new_text(MemPool mp) {
35 GwText *text = (GwText *)mp_calloc(mp, GwText);
36 text_init(text, mp);
37 return text;
38}
39
40ANN static inline void free_text(GwText *text) {
41 text_release(text);
42 mp_free(text->mp, GwText, text);
43}
44
46ANN static inline void text_reset(GwText *text) {
47 if (text->str) {
48 *text->str = '\0';
49 text->len = 0;
50 }
51}
52#endif
#define ANN
Definition defs.h:19
char * m_str
Definition gwcommon.h:14
static ANN void text_init(GwText *text, MemPool mp)
Definition gwion_text.h:18
static ANN void text_reset(GwText *text)
reset text
Definition gwion_text.h:46
static ANN void free_text(GwText *text)
Definition gwion_text.h:40
static ANN void text_release(GwText *text)
release text memory
Definition gwion_text.h:26
ANN void text_add(GwText *, const char *)
append to text
Definition text.c:12
struct GwText_ GwText
mp_allocted text
static ANN GwText * new_text(MemPool mp)
Definition gwion_text.h:34
#define mp_free2(p, sz, a)
Definition mpool.h:28
#define mp_calloc(p, name)
Definition mpool.h:26
#define mp_free(p, name, a)
Definition mpool.h:27
#define mp_malloc2(p, sz)
Definition mpool.h:30
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