gwion-util
utilities for the Gwion project
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
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 40 of file gwion_text.h.

40 {
41 text_release(text);
42 mp_free(text->mp, GwText, text);
43}
static ANN void text_release(GwText *text)
release text memory
Definition gwion_text.h:26
#define mp_free(p, name, a)
Definition mpool.h:27
mp_allocted text
Definition gwion_text.h:8
MemPool mp
Definition gwion_text.h:12

◆ new_text()

static ANN GwText * new_text ( MemPool mp)
inlinestatic

Definition at line 34 of file gwion_text.h.

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

◆ 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_init()

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

Definition at line 18 of file gwion_text.h.

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

◆ text_release()

static ANN void text_release ( GwText * text)
inlinestatic

release text memory

Definition at line 26 of file gwion_text.h.

26 {
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}
#define mp_free2(p, sz, a)
Definition mpool.h:28

◆ text_reset()

static ANN void text_reset ( GwText * text)
inlinestatic

reset text

Definition at line 46 of file gwion_text.h.

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