ucx/cx/properties.h

changeset 112
c3f2f16fa4b8
parent 108
77254bd6dccb
child 113
dde28a806552
equal deleted inserted replaced
111:81c4f73236a4 112:c3f2f16fa4b8
120 * Not used as a status and never returned by any function. 120 * Not used as a status and never returned by any function.
121 * 121 *
122 * You can use this enumerator to check for all "good" status results 122 * You can use this enumerator to check for all "good" status results
123 * by checking if the status is less than @c CX_PROPERTIES_OK. 123 * by checking if the status is less than @c CX_PROPERTIES_OK.
124 * 124 *
125 * A "good" status means, that you can refill data and continue parsing. 125 * A "good" status means that you can refill data and continue parsing.
126 */ 126 */
127 CX_PROPERTIES_OK, 127 CX_PROPERTIES_OK,
128 /** 128 /**
129 * Input buffer is @c NULL. 129 * Input buffer is @c NULL.
130 */ 130 */
131 CX_PROPERTIES_NULL_INPUT, 131 CX_PROPERTIES_NULL_INPUT,
132 /** 132 /**
133 * The line contains a delimiter, but no key. 133 * The line contains a delimiter but no key.
134 */ 134 */
135 CX_PROPERTIES_INVALID_EMPTY_KEY, 135 CX_PROPERTIES_INVALID_EMPTY_KEY,
136 /** 136 /**
137 * The line contains data, but no delimiter. 137 * The line contains data but no delimiter.
138 */ 138 */
139 CX_PROPERTIES_INVALID_MISSING_DELIMITER, 139 CX_PROPERTIES_INVALID_MISSING_DELIMITER,
140 /** 140 /**
141 * More internal buffer was needed, but could not be allocated. 141 * More internal buffer was needed, but could not be allocated.
142 */ 142 */
198 typedef struct cx_properties_sink_s CxPropertiesSink; 198 typedef struct cx_properties_sink_s CxPropertiesSink;
199 199
200 /** 200 /**
201 * A function that consumes a k/v-pair in a sink. 201 * A function that consumes a k/v-pair in a sink.
202 * 202 *
203 * The sink could be e.g. a map and the sink function would be calling 203 * The sink could be a map, and the sink function would be calling
204 * a map function to store the k/v-pair. 204 * a map function to store the k/v-pair.
205 * 205 *
206 * @param prop the properties interface that wants to sink a k/v-pair 206 * @param prop the properties interface that wants to sink a k/v-pair
207 * @param sink the sink 207 * @param sink the sink
208 * @param key the key 208 * @param key the key
295 */ 295 */
296 struct cx_properties_source_s { 296 struct cx_properties_source_s {
297 /** 297 /**
298 * The source object. 298 * The source object.
299 * 299 *
300 * For example a file stream or a string. 300 * For example, a file stream or a string.
301 */ 301 */
302 void *src; 302 void *src;
303 /** 303 /**
304 * Optional additional data pointer. 304 * Optional additional data pointer.
305 */ 305 */
337 /** 337 /**
338 * Destroys the properties interface. 338 * Destroys the properties interface.
339 * 339 *
340 * @note Even when you are certain that you did not use the interface in a 340 * @note Even when you are certain that you did not use the interface in a
341 * way that caused a memory allocation, you should call this function anyway. 341 * way that caused a memory allocation, you should call this function anyway.
342 * Future versions of the library might add features that need additional memory 342 * Future versions of the library might add features that need additional memory,
343 * and you really don't want to search the entire code where you might need 343 * and you really don't want to search the entire code where you might need to
344 * add call to this function. 344 * add a call to this function.
345 * 345 *
346 * @param prop the properties interface 346 * @param prop the properties interface
347 */ 347 */
348 cx_attr_nonnull 348 cx_attr_nonnull
349 cx_attr_export 349 cx_attr_export
350 void cxPropertiesDestroy(CxProperties *prop); 350 void cxPropertiesDestroy(CxProperties *prop);
351 351
352 /** 352 /**
353 * Destroys and re-initializes the properties interface. 353 * Destroys and re-initializes the properties interface.
354 * 354 *
355 * You might want to use this, to reset the parser after 355 * You might want to use this to reset the parser after
356 * encountering a syntax error. 356 * encountering a syntax error.
357 * 357 *
358 * @param prop the properties interface 358 * @param prop the properties interface
359 */ 359 */
360 cx_attr_nonnull 360 cx_attr_nonnull
401 CxProperties *prop, 401 CxProperties *prop,
402 const char *buf, 402 const char *buf,
403 size_t len 403 size_t len
404 ); 404 );
405 405
406 #ifdef __cplusplus 406 /**
407 } // extern "C" 407 * Internal function, do not use.
408 cx_attr_nonnull 408 *
409 static inline int cxPropertiesFill( 409 * @param prop the properties interface
410 * @param str the text to fill in
411 * @retval zero success
412 * @retval non-zero a memory allocation was necessary but failed
413 */
414 cx_attr_nonnull
415 static inline int cx_properties_fill(
410 CxProperties *prop, 416 CxProperties *prop,
411 cxstring str 417 cxstring str
412 ) { 418 ) {
413 return cxPropertiesFilln(prop, str.ptr, str.length); 419 return cxPropertiesFilln(prop, str.ptr, str.length);
414 } 420 }
415 421
416 cx_attr_nonnull
417 static inline int cxPropertiesFill(
418 CxProperties *prop,
419 cxmutstr str
420 ) {
421 return cxPropertiesFilln(prop, str.ptr, str.length);
422 }
423
424 cx_attr_nonnull
425 cx_attr_cstr_arg(2)
426 static inline int cxPropertiesFill(
427 CxProperties *prop,
428 const char *str
429 ) {
430 return cxPropertiesFilln(prop, str, strlen(str));
431 }
432
433 extern "C" {
434 #else // __cplusplus
435 /** 422 /**
436 * Fills the input buffer with data. 423 * Fills the input buffer with data.
437 * 424 *
438 * After calling this function, you can parse the data by calling 425 * After calling this function, you can parse the data by calling
439 * cxPropertiesNext(). 426 * cxPropertiesNext().
450 * @param str the text to fill in 437 * @param str the text to fill in
451 * @retval zero success 438 * @retval zero success
452 * @retval non-zero a memory allocation was necessary but failed 439 * @retval non-zero a memory allocation was necessary but failed
453 * @see cxPropertiesFilln() 440 * @see cxPropertiesFilln()
454 */ 441 */
455 #define cxPropertiesFill(prop, str) _Generic((str), \ 442 #define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str))
456 cxstring: cx_properties_fill_cxstr, \ 443
457 cxmutstr: cx_properties_fill_mutstr, \ 444 /**
458 char*: cx_properties_fill_str, \ 445 * Specifies stack memory that shall be used as an internal buffer.
459 const char*: cx_properties_fill_str) \
460 (prop, str)
461
462 /**
463 * @copydoc cxPropertiesFill()
464 */
465 cx_attr_nonnull
466 static inline int cx_properties_fill_cxstr(
467 CxProperties *prop,
468 cxstring str
469 ) {
470 return cxPropertiesFilln(prop, str.ptr, str.length);
471 }
472
473 /**
474 * @copydoc cxPropertiesFill()
475 */
476 cx_attr_nonnull
477 static inline int cx_properties_fill_mutstr(
478 CxProperties *prop,
479 cxmutstr str
480 ) {
481 return cxPropertiesFilln(prop, str.ptr, str.length);
482 }
483
484 /**
485 * @copydoc cxPropertiesFill()
486 */
487 cx_attr_nonnull
488 cx_attr_cstr_arg(2)
489 static inline int cx_properties_fill_str(
490 CxProperties *prop,
491 const char *str
492 ) {
493 return cxPropertiesFilln(prop, str, strlen(str));
494 }
495 #endif
496
497 /**
498 * Specifies stack memory that shall be used as internal buffer.
499 * 446 *
500 * @param prop the properties interface 447 * @param prop the properties interface
501 * @param buf a pointer to stack memory 448 * @param buf a pointer to stack memory
502 * @param capacity the capacity of the stack memory 449 * @param capacity the capacity of the stack memory
503 */ 450 */

mercurial