#ifndef UCX_PROPERTIES_H
#define UCX_PROPERTIES_H
#include "common.h"
#include "string.h"
#include "map.h"
#include "buffer.h"
#ifdef __cplusplus
extern "C" {
#endif
struct cx_properties_config_s {
char delimiter;
char comment1;
char comment2;
char comment3;
char continuation;
};
typedef struct cx_properties_config_s CxPropertiesConfig;
CX_EXPORT extern const CxPropertiesConfig cx_properties_config_default;
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_FILE_ERROR,
CX_PROPERTIES_MAP_ERROR,
};
typedef enum cx_properties_status CxPropertiesStatus;
struct cx_properties_s {
CxPropertiesConfig config;
CxBuffer input;
CxBuffer buffer;
};
typedef struct cx_properties_s CxProperties;
cx_attr_nonnull
CX_EXPORT void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config);
cx_attr_nonnull
CX_EXPORT void cxPropertiesDestroy(CxProperties *prop);
cx_attr_nonnull
CX_EXPORT void cxPropertiesReset(CxProperties *prop);
#define cxPropertiesInitDefault(prop) \
cxPropertiesInit(prop, cx_properties_config_default)
cx_attr_nonnull cx_attr_access_r(
2,
3)
CX_EXPORT int cxPropertiesFilln(CxProperties *prop,
const char *buf,
size_t len);
cx_attr_nonnull
CX_INLINE int cx_properties_fill(CxProperties *prop, cxstring str) {
return cxPropertiesFilln(prop, str.ptr, str.length);
}
#define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str))
cx_attr_nonnull
CX_EXPORT void cxPropertiesUseStack(CxProperties *prop,
char *buf,
size_t capacity);
cx_attr_nonnull cx_attr_nodiscard
CX_EXPORT CxPropertiesStatus cxPropertiesNext(CxProperties *prop, cxstring *key, cxstring *value);
CX_EXPORT extern const unsigned cx_properties_load_buf_size;
CX_EXPORT extern const unsigned cx_properties_load_fill_size;
cx_attr_nonnull_arg(
4)
CX_EXPORT CxPropertiesStatus cx_properties_load(CxPropertiesConfig config,
const CxAllocator *allocator, cxstring filename, CxMap *target);
#define cxPropertiesLoad(config, allocator, filename, target) \
cx_properties_load(config, allocator, cx_strcast(filename), target)
#define cxPropertiesLoadDefault(allocator, filename, target) \
cx_properties_load(cx_properties_config_default, allocator, cx_strcast(filename), target)
#ifdef __cplusplus
}
#endif
#endif