src/cx/properties.h

changeset 972
a9a1d07a6840
parent 932
484dab606292
child 980
98af3fbc847f
equal deleted inserted replaced
971:cc204fc56c9c 972:a9a1d07a6840
40 #include "string.h" 40 #include "string.h"
41 #include "map.h" 41 #include "map.h"
42 #include "array_list.h" 42 #include "array_list.h"
43 43
44 #include <stdio.h> 44 #include <stdio.h>
45 #include <string.h>
45 46
46 #ifdef __cplusplus 47 #ifdef __cplusplus
47 extern "C" { 48 extern "C" {
48 #endif 49 #endif
49 50
369 */ 370 */
370 #define cxPropertiesInitDefault(prop) \ 371 #define cxPropertiesInitDefault(prop) \
371 cxPropertiesInit(prop, cx_properties_config_default) 372 cxPropertiesInit(prop, cx_properties_config_default)
372 373
373 /** 374 /**
374 * Sets an input buffer. 375 * Fills the input buffer with data.
375 * 376 *
376 * After calling this function, you can parse the data by calling 377 * Currently unprocessed data is copied to a temporary buffer.
377 * cxPropertiesNext() until the status is #CX_PROPERTIES_NO_DATA.
378 *
379 * @param prop the properties interface
380 * @param buf a pointer to data
381 * @param len the length of the data
382 */
383 __attribute__((__nonnull__))
384 void cxPropertiesInput(
385 CxProperties *prop,
386 const char *buf,
387 size_t len
388 );
389
390 /**
391 * Sets a new input buffer after copying the current unprocessed data
392 * to a temporary buffer.
393 *
394 * This temporary buffer is allocated on the heap, unless you specified 378 * This temporary buffer is allocated on the heap, unless you specified
395 * a buffer on the stack with #cxPropertiesUseStack(). 379 * a buffer on the stack with #cxPropertiesUseStack().
396 * In that case, the stack buffer is used, until the capacity is not sufficient 380 * In that case, the stack buffer is used, until the capacity is not sufficient
397 * anymore. 381 * anymore.
398 * 382 *
399 * When this function is called without any unprocessed data that needs to be 383 * After calling this function, you can parse the data by calling
400 * copied, it behaves exactly as #cxPropertiesInput(). 384 * cxPropertiesNext() until the status is #CX_PROPERTIES_NO_DATA.
401 * 385 *
402 * @param prop the properties interface 386 * @param prop the properties interface
403 * @param buf a pointer to data 387 * @param buf a pointer to data
404 * @param len the length of the data 388 * @param len the length of the data
405 * @return non-zero when a memory allocation was necessary but failed 389 * @return non-zero when a memory allocation was necessary but failed
406 */ 390 */
407 __attribute__((__nonnull__)) 391 __attribute__((__nonnull__))
408 int cxPropertiesFill( 392 int cxPropertiesFilln(
409 CxProperties *prop, 393 CxProperties *prop,
410 const char *buf, 394 const char *buf,
411 size_t len 395 size_t len
412 ); 396 );
397
398 /**
399 * Fills the input buffer with a string.
400 *
401 * Currently unprocessed data is copied to a temporary buffer.
402 * This temporary buffer is allocated on the heap, unless you specified
403 * a buffer on the stack with #cxPropertiesUseStack().
404 * In that case, the stack buffer is used, until the capacity is not sufficient
405 * anymore.
406 *
407 * When this function is called without any unprocessed data that needs to be
408 * copied, it behaves exactly as #cxPropertiesInput().
409 *
410 * @param prop the properties interface
411 * @param str the string
412 * @return non-zero when a memory allocation was necessary but failed
413 */
414 #define cxPropertiesFill(prop, str) _Generic((str), \
415 cxstring: cx_properties_fill_cxstr, \
416 cxmutstr: cx_properties_fill_mutstr, \
417 char*: cx_properties_fill_str, \
418 const char*: cx_properties_fill_str) \
419 (prop, str)
420
421 /**
422 * Implementation of cxPropertiesFill() for cxstring.
423 *
424 * @param prop the properties interface
425 * @param str the string
426 * @return non-zero when a memory allocation was necessary but failed
427 */
428 __attribute__((__nonnull__))
429 static inline int cx_properties_fill_cxstr(
430 CxProperties *prop,
431 cxstring str
432 ) {
433 return cxPropertiesFilln(prop, str.ptr, str.length);
434 }
435
436 /**
437 * Implementation of cxPropertiesFill() for cxmutstr.
438 *
439 * @param prop the properties interface
440 * @param str the string
441 * @return non-zero when a memory allocation was necessary but failed
442 */
443 __attribute__((__nonnull__))
444 static inline int cx_properties_fill_mutstr(
445 CxProperties *prop,
446 cxmutstr str
447 ) {
448 return cxPropertiesFilln(prop, str.ptr, str.length);
449 }
450
451 /**
452 * Implementation of cxPropertiesFill() for zero terminated C strings.
453 *
454 * @param prop the properties interface
455 * @param str the string
456 * @return non-zero when a memory allocation was necessary but failed
457 */
458 __attribute__((__nonnull__))
459 static inline int cx_properties_fill_str(
460 CxProperties *prop,
461 const char *str
462 ) {
463 return cxPropertiesFilln(prop, str, strlen(str));
464 }
413 465
414 /** 466 /**
415 * Specifies stack memory that shall be used by #cxPropertiesFill(). 467 * Specifies stack memory that shall be used by #cxPropertiesFill().
416 * 468 *
417 * @param prop the properties interface 469 * @param prop the properties interface

mercurial