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
30
31
32
33
34
35
36 #ifndef UCX_PROPERTIES_H
37 #define UCX_PROPERTIES_H
38
39 #include "common.h"
40 #include "string.h"
41 #include "map.h"
42 #include "buffer.h"
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48
49
50
51 struct cx_properties_config_s {
52
53
54
55
56 char delimiter;
57
58
59
60
61
62 char comment1;
63
64
65
66
67
68 char comment2;
69
70
71
72
73
74 char comment3;
75
76
77
78
79
80 char continuation;
81 };
82
83
84
85
86 typedef struct cx_properties_config_s CxPropertiesConfig;
87
88
89
90
91 CX_EXPORT extern const CxPropertiesConfig cx_properties_config_default;
92
93
94
95
96 enum cx_properties_status {
97
98
99
100 CX_PROPERTIES_NO_ERROR,
101
102
103
104 CX_PROPERTIES_NO_DATA,
105
106
107
108
109
110
111 CX_PROPERTIES_INCOMPLETE_DATA,
112
113
114
115
116
117
118
119
120 CX_PROPERTIES_OK,
121
122
123
124 CX_PROPERTIES_NULL_INPUT,
125
126
127
128 CX_PROPERTIES_INVALID_EMPTY_KEY,
129
130
131
132 CX_PROPERTIES_INVALID_MISSING_DELIMITER,
133
134
135
136 CX_PROPERTIES_BUFFER_ALLOC_FAILED,
137
138
139
140
141
142 CX_PROPERTIES_FILE_ERROR,
143
144
145
146
147 CX_PROPERTIES_MAP_ERROR,
148 };
149
150
151
152
153 typedef enum cx_properties_status CxPropertiesStatus;
154
155
156
157
158 struct cx_properties_s {
159
160
161
162 CxPropertiesConfig config;
163
164
165
166
167 CxBuffer input;
168
169
170
171
172 CxBuffer buffer;
173 };
174
175
176
177
178 typedef struct cx_properties_s CxProperties;
179
180
181
182
183
184
185
186
187 cx_attr_nonnull
188 CX_EXPORT void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
189
190
191
192
193
194
195
196
197
198
199
200
201 cx_attr_nonnull
202 CX_EXPORT void cxPropertiesDestroy(CxProperties *prop);
203
204
205
206
207
208
209
210
211
212 cx_attr_nonnull
213 CX_EXPORT void cxPropertiesReset(CxProperties *prop);
214
215
216
217
218
219
220
221 #define cxPropertiesInitDefault(prop) \
222 cxPropertiesInit(prop, cx_properties_config_default)
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245 cx_attr_nonnull cx_attr_access_r(
2,
3)
246 CX_EXPORT int cxPropertiesFilln(CxProperties *prop,
const char *buf,
size_t len);
247
248
249
250
251
252
253
254
255
256 cx_attr_nonnull
257 CX_INLINE int cx_properties_fill(CxProperties *prop, cxstring str) {
258 return cxPropertiesFilln(prop, str.ptr, str.length);
259 }
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281 #define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str))
282
283
284
285
286
287
288
289
290 cx_attr_nonnull
291 CX_EXPORT void cxPropertiesUseStack(CxProperties *prop,
char *buf,
size_t capacity);
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323 cx_attr_nonnull cx_attr_nodiscard
324 CX_EXPORT CxPropertiesStatus cxPropertiesNext(CxProperties *prop, cxstring *key, cxstring *value);
325
326
327
328
329 CX_EXPORT extern const unsigned cx_properties_load_buf_size;
330
331
332
333
334 CX_EXPORT extern const unsigned cx_properties_load_fill_size;
335
336
337
338
339
340
341
342
343
344
345 cx_attr_nonnull_arg(
4)
346 CX_EXPORT CxPropertiesStatus cx_properties_load(CxPropertiesConfig config,
347 const CxAllocator *allocator, cxstring filename, CxMap *target);
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374 #define cxPropertiesLoad(config, allocator, filename, target) \
375 cx_properties_load(config, allocator, cx_strcast(filename), target)
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401 #define cxPropertiesLoadDefault(allocator, filename, target) \
402 cx_properties_load(cx_properties_config_default, allocator, cx_strcast(filename), target)
403
404
405 #ifdef __cplusplus
406 }
407 #endif
408
409 #endif
410