gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
gwion_text.h File Reference

text structure and functions More...

Go to the source code of this file.

Data Structures

struct  GwText_
 mp_allocted text More...
 

Typedefs

typedef struct GwText_ GwText
 mp_allocted text
 

Functions

ANN void text_add (GwText *, const char *)
 append to text
 
static ANN void text_init (GwText *text, MemPool mp)
 
static ANN void text_release (GwText *text)
 release text memory
 
static ANN GwTextnew_text (MemPool mp)
 
static ANN void free_text (GwText *text)
 
static ANN void text_reset (GwText *text)
 reset text
 

Detailed Description

text structure and functions

Definition in file gwion_text.h.

Typedef Documentation

◆ GwText

typedef struct GwText_ GwText

mp_allocted text

Function Documentation

◆ free_text()

static ANN void free_text ( GwText * text)
inlinestatic

Definition at line 39 of file gwion_text.h.

39 {
40 text_release(text);
41 mp_free(text->mp, GwText, text);
42}
static ANN void text_release(GwText *text)
release text memory
Definition gwion_text.h:25
struct GwText_ GwText
mp_allocted text
#define mp_free(p, name, a)
Definition mpool.h:25
MemPool mp
Definition gwion_text.h:11

◆ new_text()

static ANN GwText * new_text ( MemPool mp)
inlinestatic

Definition at line 33 of file gwion_text.h.

33 {
34 GwText *text = (GwText *)mp_calloc(mp, GwText);
35 text_init(text, mp);
36 return text;
37}
static ANN void text_init(GwText *text, MemPool mp)
Definition gwion_text.h:17
#define mp_calloc(p, name)
Definition mpool.h:24

◆ 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:10
static ANN m_str text_grow(GwText *text, const size_t sz)
Definition text.c:3

◆ text_init()

static ANN void text_init ( GwText * text,
MemPool mp )
inlinestatic

Definition at line 17 of file gwion_text.h.

17 {
18 text->mp = mp;
19 text->str = (m_str)mp_malloc2(mp, 64);
20 text->len = 0;
21 text->cap = 64;
22}
char * m_str
Definition gwcommon.h:15
#define mp_malloc2(p, sz)
Definition mpool.h:28
size_t cap
Definition gwion_text.h:9
m_str str
Definition gwion_text.h:8

◆ text_release()

static ANN void text_release ( GwText * text)
inlinestatic

release text memory

Definition at line 25 of file gwion_text.h.

25 {
26 if (text->str) {
27 mp_free2(text->mp, text->cap, text->str);
28 text->str = NULL;
29 text->cap = text->len = 0;
30 }
31}
#define mp_free2(p, sz, a)
Definition mpool.h:26

◆ text_reset()

static ANN void text_reset ( GwText * text)
inlinestatic

reset text

Definition at line 45 of file gwion_text.h.

45 {
46 if (text->str) {
47 *text->str = '\0';
48 text->len = 0;
49 }
50}