1 #if !defined( CSTRING_H )
5 * An implementation of expandable c strings in heap memory.
6 * Copyright (C) 2018 Michael Goehler
8 * This file is part of mdp.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * struct: cstring_t which defines a expandable c string type in heap memory
26 * function: cstring_init to initialize struct of type cstring_t
27 * function: cstring_t->expand to add one character to the struct
28 * function: cstring_t->expand_arr to add a string to the struct
29 * function: cstring_t->strip to remove a substring
30 * function: cstring_t->reset to clear and reuse the struct
31 * function: cstring_t->delete to free the allocated memory
34 * cstring_t *p = cstring_init();
35 * (p->expand)(p, 'X');
40 // The amount of memory allocated from heap when string expansion hits the
41 // allocated memory limit
42 #define REALLOC_ADD 10
44 typedef struct _cstring_t {
48 void (*expand)(struct _cstring_t *self, wchar_t x);
49 void (*expand_arr)(struct _cstring_t *self, wchar_t *x);
50 void (*strip)(struct _cstring_t *self, int pos, int len);
51 void (*reset)(struct _cstring_t *self);
52 void (*delete)(struct _cstring_t *self);
55 cstring_t *cstring_init();
56 void cstring_expand(cstring_t *self, wchar_t x);
57 void cstring_expand_arr(cstring_t *self, wchar_t *x);
58 void cstring_strip(cstring_t *self, int pos, int len);
59 void cstring_reset(cstring_t *self);
60 void cstring_delete(cstring_t *self);
62 #endif // !defined( CSTRING_H )