36#ifndef UCX_PROPERTIES_H
37#define UCX_PROPERTIES_H
373#define cxPropertiesInitDefault(prop) \
374 cxPropertiesInit(prop, cx_properties_config_default)
455#define cxPropertiesFill(prop, str) _Generic((str), \
456 cxstring: cx_properties_fill_cxstr, \
457 cxmutstr: cx_properties_fill_mutstr, \
458 char*: cx_properties_fill_str, \
459 const char*: cx_properties_fill_str) \
Advanced buffer implementation.
Common definitions and feature checks.
#define cx_attr_nonnull
All pointer arguments must be non-NULL.
Definition common.h:136
#define cx_attr_nodiscard
Warn about discarded return value.
Definition common.h:265
#define cx_attr_access_r(...)
Specifies that the function will only read through the given pointer.
Definition common.h:225
#define cx_attr_cstr_arg(idx)
No support for null_terminated_string_arg in clang or GCC below 14.
Definition common.h:206
Interface for map implementations.
static int cx_properties_fill_str(CxProperties *prop, const char *str)
Fills the input buffer with data.
Definition properties.h:489
static int cx_properties_fill_mutstr(CxProperties *prop, cxmutstr str)
Fills the input buffer with data.
Definition properties.h:477
static int cx_properties_fill_cxstr(CxProperties *prop, cxstring str)
Fills the input buffer with data.
Definition properties.h:466
CxPropertiesSource cxPropertiesCstrSource(const char *str)
Creates a properties source based on a C string.
void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config)
Initialize a properties interface.
int(* cx_properties_read_init_func)(CxProperties *prop, CxPropertiesSource *src)
A function that may initialize additional memory for the source.
Definition properties.h:276
int(* cx_properties_read_func)(CxProperties *prop, CxPropertiesSource *src, cxstring *target)
A function that reads data from a source.
Definition properties.h:261
const CxPropertiesConfig cx_properties_config_default
Default properties configuration.
void cxPropertiesDestroy(CxProperties *prop)
Destroys the properties interface.
CxPropertiesStatus cxPropertiesNext(CxProperties *prop, cxstring *key, cxstring *value)
Retrieves the next key/value-pair.
CxPropertiesSource cxPropertiesCstrnSource(const char *str, size_t len)
Creates a properties source based on C string with the specified length.
int(* cx_properties_sink_func)(CxProperties *prop, CxPropertiesSink *sink, cxstring key, cxstring value)
A function that consumes a k/v-pair in a sink.
Definition properties.h:214
int cxPropertiesFilln(CxProperties *prop, const char *buf, size_t len)
Fills the input buffer with data.
CxPropertiesSource cxPropertiesFileSource(FILE *file, size_t chunk_size)
Creates a properties source based on an FILE.
CxPropertiesStatus cxPropertiesLoad(CxProperties *prop, CxPropertiesSink sink, CxPropertiesSource source)
Loads properties data from a source and transfers it to a sink.
CxPropertiesSink cxPropertiesMapSink(CxMap *map)
Creates a properties sink for an UCX map.
CxPropertiesSource cxPropertiesStringSource(cxstring str)
Creates a properties source based on an UCX string.
#define cxPropertiesFill(prop, str)
Fills the input buffer with data.
Definition properties.h:455
void cxPropertiesUseStack(CxProperties *prop, char *buf, size_t capacity)
Specifies stack memory that shall be used as internal buffer.
void(* cx_properties_read_clean_func)(CxProperties *prop, CxPropertiesSource *src)
A function that cleans memory initialized by the read_init_func.
Definition properties.h:288
cx_properties_status
Status codes for the properties interface.
Definition properties.h:103
@ CX_PROPERTIES_SINK_FAILED
Sinking a k/v-pair failed.
Definition properties.h:161
@ CX_PROPERTIES_NO_ERROR
Everything is fine.
Definition properties.h:107
@ CX_PROPERTIES_INVALID_EMPTY_KEY
The line contains a delimiter, but no key.
Definition properties.h:135
@ CX_PROPERTIES_OK
Not used as a status and never returned by any function.
Definition properties.h:127
@ CX_PROPERTIES_NULL_INPUT
Input buffer is NULL.
Definition properties.h:131
@ CX_PROPERTIES_READ_FAILED
Reading from a properties source failed.
Definition properties.h:155
@ CX_PROPERTIES_INCOMPLETE_DATA
The input ends unexpectedly.
Definition properties.h:118
@ CX_PROPERTIES_READ_INIT_FAILED
Initializing the properties source failed.
Definition properties.h:149
@ CX_PROPERTIES_BUFFER_ALLOC_FAILED
More internal buffer was needed, but could not be allocated.
Definition properties.h:143
@ CX_PROPERTIES_NO_DATA
The input buffer does not contain more data.
Definition properties.h:111
@ CX_PROPERTIES_INVALID_MISSING_DELIMITER
The line contains data, but no delimiter.
Definition properties.h:139
enum cx_properties_status CxPropertiesStatus
Typedef for the properties status enum.
Definition properties.h:167
static void cxPropertiesReset(CxProperties *prop)
Destroys and re-initializes the properties interface.
Definition properties.h:361
Strings that know their length.
Structure for the UCX buffer data.
Definition buffer.h:157
Structure for the UCX map.
Definition map.h:61
The UCX string structure.
Definition string.h:51
char * ptr
A pointer to the string.
Definition string.h:56
size_t length
The length of the string.
Definition string.h:58
Configures the expected characters for the properties parser.
Definition properties.h:54
char continuation
Reserved for future use.
Definition properties.h:86
char delimiter
The key/value delimiter that shall be used.
Definition properties.h:59
char comment3
The third comment character.
Definition properties.h:77
char comment2
The second comment character.
Definition properties.h:71
char comment1
The first comment character.
Definition properties.h:65
Interface for working with properties data.
Definition properties.h:172
CxBuffer input
The text input buffer.
Definition properties.h:181
CxPropertiesConfig config
The configuration.
Definition properties.h:176
CxBuffer buffer
Internal buffer.
Definition properties.h:186
Defines a sink for k/v-pairs.
Definition properties.h:224
cx_properties_sink_func sink_func
A function for consuming k/v-pairs into the sink.
Definition properties.h:236
void * sink
The sink object.
Definition properties.h:228
void * data
Optional custom data.
Definition properties.h:232
Defines a properties source.
Definition properties.h:296
cx_properties_read_init_func read_init_func
Optional function that may prepare the source for reading data.
Definition properties.h:318
void * src
The source object.
Definition properties.h:302
void * data_ptr
Optional additional data pointer.
Definition properties.h:306
size_t data_size
Optional size information.
Definition properties.h:310
cx_properties_read_func read_func
A function that reads data from the source.
Definition properties.h:314
cx_properties_read_clean_func read_clean_func
Optional function that cleans additional memory allocated by the read_init_func.
Definition properties.h:323
The UCX string structure for immutable (constant) strings.
Definition string.h:69
size_t length
The length of the string.
Definition string.h:76
const char * ptr
A pointer to the immutable string.
Definition string.h:74