1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef STRINGREPLACE_H
30 #define STRINGREPLACE_H
31
32 #include "../public/nsapi.h"
33
34 #include <cx/string.h>
35 #include <cx/buffer.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 typedef enum StringSegmentType {
42
43
44
45 STRING_SEGMENT_STR =
0,
46
47
48
49 STRING_SEGMENT_NUM_PLACEHOLDER,
50
51
52
53 STRING_SEGMENT_VAR_PLACEHOLDER
54 } StringSegmentType;
55
56 typedef struct StringTemplateSegment StringTemplateSegment;
57 typedef struct StringTemplate StringTemplate;
58
59 struct StringTemplate {
60 const CxAllocator *a;
61 StringTemplateSegment *segments;
62 };
63
64 struct StringTemplateSegment {
65
66
67
68
69
70 cxmutstr str;
71
72
73
74
75 StringSegmentType type;
76
77
78
79
80 int num;
81
82
83
84
85 StringTemplateSegment *next;
86 };
87
88
89
90
91
92
93
94
95
96
97 typedef cxmutstr (*strtpl_var_func)(
const CxAllocator *a, StringTemplateSegment *seg,
void *userdata, WSBool *free_str);
98
99
100
101
102
103
104
105 StringTemplate* string_template_compile(
const CxAllocator *a, cxstring tpl);
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 ssize_t string_template_write_to(StringTemplate *tpl,
const CxAllocator *a, strtpl_var_func varfunc,
void *userdata,
void *stream, cx_write_func writef);
121
122
123
124
125 cxmutstr string_template_build_string(StringTemplate *tpl,
const CxAllocator *a, strtpl_var_func varfunc,
void *userdata);
126
127 void string_template_free(StringTemplate *tpl);
128
129 #ifdef __cplusplus
130 }
131 #endif
132
133 #endif
134
135