![]() |
ucx
UAP Common Extensions
|
Interface for parsing data from properties files. More...
Go to the source code of this file.
Data Structures | |
struct | cx_properties_config_s |
Configures the expected characters for the properties parser. More... | |
struct | cx_properties_s |
Interface for working with properties data. More... | |
struct | cx_properties_sink_s |
Defines a sink for k/v-pairs. More... | |
struct | cx_properties_source_s |
Defines a properties source. More... | |
Macros | |
#define | cxPropertiesInitDefault(prop) cxPropertiesInit(prop, cx_properties_config_default) |
Initialize a properties parser with the default configuration. | |
#define | cxPropertiesFill(prop, str) |
Fills the input buffer with data. | |
Typedefs | |
typedef struct cx_properties_config_s | CxPropertiesConfig |
Typedef for the properties config. | |
typedef enum cx_properties_status | CxPropertiesStatus |
Typedef for the properties status enum. | |
typedef struct cx_properties_s | CxProperties |
Typedef for the properties interface. | |
typedef struct cx_properties_sink_s | CxPropertiesSink |
Typedef for a properties sink. | |
typedef int(* | cx_properties_sink_func) (CxProperties *prop, CxPropertiesSink *sink, cxstring key, cxstring value) |
A function that consumes a k/v-pair in a sink. | |
typedef struct cx_properties_source_s | CxPropertiesSource |
Typedef for a properties source. | |
typedef int(* | cx_properties_read_func) (CxProperties *prop, CxPropertiesSource *src, cxstring *target) |
A function that reads data from a source. | |
typedef int(* | cx_properties_read_init_func) (CxProperties *prop, CxPropertiesSource *src) |
A function that may initialize additional memory for the source. | |
typedef void(* | cx_properties_read_clean_func) (CxProperties *prop, CxPropertiesSource *src) |
A function that cleans memory initialized by the read_init_func. | |
Enumerations | |
enum | cx_properties_status { CX_PROPERTIES_NO_ERROR , CX_PROPERTIES_NO_DATA , CX_PROPERTIES_INCOMPLETE_DATA , CX_PROPERTIES_OK , CX_PROPERTIES_NULL_INPUT , CX_PROPERTIES_INVALID_EMPTY_KEY , CX_PROPERTIES_INVALID_MISSING_DELIMITER , CX_PROPERTIES_BUFFER_ALLOC_FAILED , CX_PROPERTIES_READ_INIT_FAILED , CX_PROPERTIES_READ_FAILED , CX_PROPERTIES_SINK_FAILED } |
Status codes for the properties interface. More... | |
Functions | |
void | cxPropertiesInit (CxProperties *prop, CxPropertiesConfig config) |
Initialize a properties interface. | |
void | cxPropertiesDestroy (CxProperties *prop) |
Destroys the properties interface. | |
static void | cxPropertiesReset (CxProperties *prop) |
Destroys and re-initializes the properties interface. | |
int | cxPropertiesFilln (CxProperties *prop, const char *buf, size_t len) |
Fills the input buffer with data. | |
static int | cx_properties_fill_cxstr (CxProperties *prop, cxstring str) |
Fills the input buffer with data. | |
static int | cx_properties_fill_mutstr (CxProperties *prop, cxmutstr str) |
Fills the input buffer with data. | |
static int | cx_properties_fill_str (CxProperties *prop, const char *str) |
Fills the input buffer with data. | |
void | cxPropertiesUseStack (CxProperties *prop, char *buf, size_t capacity) |
Specifies stack memory that shall be used as internal buffer. | |
CxPropertiesStatus | cxPropertiesNext (CxProperties *prop, cxstring *key, cxstring *value) |
Retrieves the next key/value-pair. | |
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. | |
CxPropertiesSource | cxPropertiesCstrnSource (const char *str, size_t len) |
Creates a properties source based on C string with the specified length. | |
CxPropertiesSource | cxPropertiesCstrSource (const char *str) |
Creates a properties source based on a C string. | |
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. | |
Variables | |
const CxPropertiesConfig | cx_properties_config_default |
Default properties configuration. | |
Interface for parsing data from properties files.
#define cxPropertiesFill | ( | prop, | |
str ) |
Fills the input buffer with data.
After calling this function, you can parse the data by calling cxPropertiesNext().
prop | the properties interface |
str | the text to fill in |
zero | success |
non-zero | a memory allocation was necessary but failed |
#define cxPropertiesInitDefault | ( | prop | ) | cxPropertiesInit(prop, cx_properties_config_default) |
Initialize a properties parser with the default configuration.
prop | (CxProperties* ) the properties interface |
typedef void(* cx_properties_read_clean_func) (CxProperties *prop, CxPropertiesSource *src) |
A function that cleans memory initialized by the read_init_func.
prop | the properties interface that wants to read from the source |
src | the source |
typedef int(* cx_properties_read_func) (CxProperties *prop, CxPropertiesSource *src, cxstring *target) |
A function that reads data from a source.
When the source is depleted, implementations SHALL provide an empty string in the target
and return zero. A non-zero return value is only permitted in case of an error.
The meaning of the optional parameters is implementation-dependent.
prop | the properties interface that wants to read from the source |
src | the source |
target | a string buffer where the read data shall be stored |
zero | success |
non-zero | reading the data failed |
typedef int(* cx_properties_read_init_func) (CxProperties *prop, CxPropertiesSource *src) |
A function that may initialize additional memory for the source.
prop | the properties interface that wants to read from the source |
src | the source |
zero | initialization was successful |
non-zero | otherwise |
typedef int(* cx_properties_sink_func) (CxProperties *prop, CxPropertiesSink *sink, cxstring key, cxstring value) |
A function that consumes a k/v-pair in a sink.
The sink could be e.g. a map and the sink function would be calling a map function to store the k/v-pair.
prop | the properties interface that wants to sink a k/v-pair |
sink | the sink |
key | the key |
value | the value |
zero | success |
non-zero | sinking the k/v-pair failed |
enum cx_properties_status |
Status codes for the properties interface.
Enumerator | |
---|---|
CX_PROPERTIES_NO_ERROR | Everything is fine. |
CX_PROPERTIES_NO_DATA | The input buffer does not contain more data. |
CX_PROPERTIES_INCOMPLETE_DATA | The input ends unexpectedly. This either happens when the last line does not terminate with a line break, or when the input ends with a parsed key but no value. |
CX_PROPERTIES_OK | Not used as a status and never returned by any function. You can use this enumerator to check for all "good" status results by checking if the status is less than A "good" status means, that you can refill data and continue parsing. |
CX_PROPERTIES_NULL_INPUT | Input buffer is |
CX_PROPERTIES_INVALID_EMPTY_KEY | The line contains a delimiter, but no key. |
CX_PROPERTIES_INVALID_MISSING_DELIMITER | The line contains data, but no delimiter. |
CX_PROPERTIES_BUFFER_ALLOC_FAILED | More internal buffer was needed, but could not be allocated. |
CX_PROPERTIES_READ_INIT_FAILED | Initializing the properties source failed.
|
CX_PROPERTIES_READ_FAILED | Reading from a properties source failed.
|
CX_PROPERTIES_SINK_FAILED | Sinking a k/v-pair failed.
|
|
inlinestatic |
Fills the input buffer with data.
After calling this function, you can parse the data by calling cxPropertiesNext().
prop | the properties interface |
str | the text to fill in |
zero | success |
non-zero | a memory allocation was necessary but failed |
|
inlinestatic |
Fills the input buffer with data.
After calling this function, you can parse the data by calling cxPropertiesNext().
prop | the properties interface |
str | the text to fill in |
zero | success |
non-zero | a memory allocation was necessary but failed |
|
inlinestatic |
Fills the input buffer with data.
After calling this function, you can parse the data by calling cxPropertiesNext().
prop | the properties interface |
str | the text to fill in |
zero | success |
non-zero | a memory allocation was necessary but failed |
CxPropertiesSource cxPropertiesCstrnSource | ( | const char * | str, |
size_t | len ) |
Creates a properties source based on C string with the specified length.
str | the string |
len | the length |
CxPropertiesSource cxPropertiesCstrSource | ( | const char * | str | ) |
Creates a properties source based on a C string.
The length will be determined with strlen(), so the string MUST be zero-terminated.
str | the string |
void cxPropertiesDestroy | ( | CxProperties * | prop | ) |
Destroys the properties interface.
prop | the properties interface |
CxPropertiesSource cxPropertiesFileSource | ( | FILE * | file, |
size_t | chunk_size ) |
Creates a properties source based on an FILE.
file | the file |
chunk_size | how many bytes may be read in one operation |
int cxPropertiesFilln | ( | CxProperties * | prop, |
const char * | buf, | ||
size_t | len ) |
Fills the input buffer with data.
After calling this function, you can parse the data by calling cxPropertiesNext().
prop | the properties interface |
buf | a pointer to the data |
len | the length of the data |
zero | success |
non-zero | a memory allocation was necessary but failed |
void cxPropertiesInit | ( | CxProperties * | prop, |
CxPropertiesConfig | config ) |
Initialize a properties interface.
prop | the properties interface |
config | the properties configuration |
CxPropertiesStatus cxPropertiesLoad | ( | CxProperties * | prop, |
CxPropertiesSink | sink, | ||
CxPropertiesSource | source ) |
Loads properties data from a source and transfers it to a sink.
This function tries to read as much data from the source as possible. When the source was completely consumed and at least on k/v-pair was found, the return value will be CX_PROPERTIES_NO_ERROR. When the source was consumed but no k/v-pairs were found, the return value will be CX_PROPERTIES_NO_DATA. In case the source data ends unexpectedly, the CX_PROPERTIES_INCOMPLETE_DATA is returned. In that case you should call this function again with the same sink and either an updated source or the same source if the source is able to yield the missing data.
The other result codes apply, according to their description.
prop | the properties interface |
sink | the sink |
source | the source |
CX_PROPERTIES_NO_ERROR | (zero) a key/value pair was found |
CX_PROPERTIES_READ_INIT_FAILED | initializing the source failed |
CX_PROPERTIES_READ_FAILED | reading from the source failed |
CX_PROPERTIES_SINK_FAILED | sinking the properties into the sink failed |
CX_PROPERTIES_NO_DATA | the source did not provide any key/value pairs |
CX_PROPERTIES_INCOMPLETE_DATA | the source did not provide enough data |
CX_PROPERTIES_INVALID_EMPTY_KEY | the properties data contains an illegal empty key |
CX_PROPERTIES_INVALID_MISSING_DELIMITER | the properties data contains a line without delimiter |
CX_PROPERTIES_BUFFER_ALLOC_FAILED | an internal allocation was necessary but failed |
CxPropertiesSink cxPropertiesMapSink | ( | CxMap * | map | ) |
Creates a properties sink for an UCX map.
The values stored in the map will be pointers to strings allocated by cx_strdup_a(). The default stdlib allocator will be used, unless you specify a custom allocator in the optional data
of the sink.
map | the map that shall consume the k/v-pairs. |
CxPropertiesStatus cxPropertiesNext | ( | CxProperties * | prop, |
cxstring * | key, | ||
cxstring * | value ) |
Retrieves the next key/value-pair.
This function returns zero as long as there are key/value-pairs found. If no more key/value-pairs are found, CX_PROPERTIES_NO_DATA is returned.
When an incomplete line is encountered, CX_PROPERTIES_INCOMPLETE_DATA is returned, and you can add more data with cxPropertiesFill().
prop | the properties interface |
key | a pointer to the cxstring that shall contain the property name |
value | a pointer to the cxstring that shall contain the property value |
CX_PROPERTIES_NO_ERROR | (zero) a key/value pair was found |
CX_PROPERTIES_NO_DATA | there is no (more) data in the input buffer |
CX_PROPERTIES_INCOMPLETE_DATA | the data in the input buffer is incomplete (fill more data and try again) |
CX_PROPERTIES_NULL_INPUT | the input buffer was never filled |
CX_PROPERTIES_INVALID_EMPTY_KEY | the properties data contains an illegal empty key |
CX_PROPERTIES_INVALID_MISSING_DELIMITER | the properties data contains a line without delimiter |
CX_PROPERTIES_BUFFER_ALLOC_FAILED | an internal allocation was necessary but failed |
|
inlinestatic |
Destroys and re-initializes the properties interface.
You might want to use this, to reset the parser after encountering a syntax error.
prop | the properties interface |
CxPropertiesSource cxPropertiesStringSource | ( | cxstring | str | ) |
Creates a properties source based on an UCX string.
str | the string |
void cxPropertiesUseStack | ( | CxProperties * | prop, |
char * | buf, | ||
size_t | capacity ) |
Specifies stack memory that shall be used as internal buffer.
prop | the properties interface |
buf | a pointer to stack memory |
capacity | the capacity of the stack memory |