ucx
UAP Common Extensions
Loading...
Searching...
No Matches
properties.h
Go to the documentation of this file.
1/*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
35
36#ifndef UCX_PROPERTIES_H
37#define UCX_PROPERTIES_H
38
39#include "common.h"
40#include "string.h"
41#include "map.h"
42#include "buffer.h"
43
53
59
65
71
77};
78
83
88
145
150
170
175
185
199
210
217#define cxPropertiesInitDefault(prop) \
218 cxPropertiesInit(prop, cx_properties_config_default)
219
242int cxPropertiesFilln(CxProperties *prop, const char *buf, size_t len);
243
254 return cxPropertiesFilln(prop, str.ptr, str.length);
255}
256
277#define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str))
278
287void cxPropertiesUseStack(CxProperties *prop, char *buf, size_t capacity);
288
321
325CX_EXPORT extern const unsigned cx_properties_load_buf_size;
326
330CX_EXPORT extern const unsigned cx_properties_load_fill_size;
331
343 cxstring filename, CxMap *target, CxPropertiesConfig config);
344
370#define cxPropertiesLoad(allocator, filename, target, config) \
371 cx_properties_load(allocator, cx_strcast(filename), target, config)
372
397#define cxPropertiesLoadDefault(allocator, filename, target) \
398 cx_properties_load(allocator, cx_strcast(filename), target, cx_properties_config_default)
399
400#endif // UCX_PROPERTIES_H
struct cx_allocator_s CxAllocator
High-Level type alias for the allocator type.
Definition allocator.h:80
Advanced buffer implementation.
struct cx_buffer_s CxBuffer
UCX buffer.
Definition buffer.h:143
Common definitions and feature checks.
#define CX_INLINE
Declares a function to be inlined.
Definition common.h:311
#define CX_EXPORT
Only used for building Windows DLLs.
Definition common.h:289
#define CX_NONNULL
All pointer arguments must be non-NULL.
Definition common.h:141
#define CX_NODISCARD
Warn about discarded return value.
Definition common.h:256
#define CX_NONNULL_ARG(...)
The specified pointer arguments must be non-NULL.
Definition common.h:146
#define CX_EXTERN
Declares a function with external linkage.
Definition common.h:297
#define CX_ACCESS_R(...)
Specifies that the function will only read through the given pointer.
Definition common.h:230
Interface for map implementations.
struct cx_map_s CxMap
Type for the UCX map.
Definition map.h:50
void cxPropertiesInit(CxProperties *prop, CxPropertiesConfig config)
Initialize a properties interface.
void cxPropertiesReset(CxProperties *prop)
Destroys and re-initializes the properties interface.
CxPropertiesStatus cx_properties_load(const CxAllocator *allocator, cxstring filename, CxMap *target, CxPropertiesConfig config)
Internal function - use cxPropertiesLoad() instead.
const unsigned cx_properties_load_fill_size
The size of the stack memory that cxPropertiesLoad() will use to read contents from the file.
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.
int cxPropertiesFilln(CxProperties *prop, const char *buf, size_t len)
Fills the input buffer with data.
struct cx_properties_config_s CxPropertiesConfig
Typedef for the properties config.
Definition properties.h:82
static int cx_properties_fill(CxProperties *prop, cxstring str)
Internal function, do not use.
Definition properties.h:253
void cxPropertiesUseStack(CxProperties *prop, char *buf, size_t capacity)
Specifies stack memory that shall be used as an internal buffer.
struct cx_properties_s CxProperties
Typedef for the properties interface.
Definition properties.h:174
cx_properties_status
Status codes for the properties interface.
Definition properties.h:92
@ CX_PROPERTIES_NO_ERROR
Everything is fine.
Definition properties.h:96
@ CX_PROPERTIES_MAP_ERROR
A map operation failed.
Definition properties.h:143
@ CX_PROPERTIES_INVALID_EMPTY_KEY
The line contains a delimiter but no key.
Definition properties.h:124
@ CX_PROPERTIES_OK
Not used as a status and never returned by any function.
Definition properties.h:116
@ CX_PROPERTIES_FILE_ERROR
A file operation failed.
Definition properties.h:138
@ CX_PROPERTIES_NULL_INPUT
Input buffer is NULL.
Definition properties.h:120
@ CX_PROPERTIES_INCOMPLETE_DATA
The input ends unexpectedly.
Definition properties.h:107
@ CX_PROPERTIES_BUFFER_ALLOC_FAILED
More internal buffer was needed, but could not be allocated.
Definition properties.h:132
@ CX_PROPERTIES_NO_DATA
The input buffer does not contain more data.
Definition properties.h:100
@ CX_PROPERTIES_INVALID_MISSING_DELIMITER
The line contains data but no delimiter.
Definition properties.h:128
enum cx_properties_status CxPropertiesStatus
Typedef for the properties status enum.
Definition properties.h:149
const unsigned cx_properties_load_buf_size
The size of the stack memory that cxPropertiesLoad() will reserve with cxPropertiesUseStack().
Strings that know their length.
struct cx_string_s cxstring
An immutable string.
Definition string.h:92
Configures the expected characters for the properties parser.
Definition properties.h:47
char continuation
The character, when appearing at the end of a line, continues that line.
Definition properties.h:76
char delimiter
The key/value delimiter that shall be used.
Definition properties.h:52
char comment3
The third comment character.
Definition properties.h:70
char comment2
The second comment character.
Definition properties.h:64
char comment1
The first comment character.
Definition properties.h:58
Interface for working with properties data.
Definition properties.h:154
CxBuffer input
The text input buffer.
Definition properties.h:163
CxPropertiesConfig config
The configuration.
Definition properties.h:158
CxBuffer buffer
Internal buffer.
Definition properties.h:168