Simple parser for "key = value" text files, by zamaz. More...
#include <stddef.h>
Go to the source code of this file.
Classes | |
struct | ckvp_t |
ckvp_t stores the state, it must be initialized with CKVP_INIT before being fed to ckvp_parse(). More... |
Macros | |
#define | CKVP_DECL_BEGIN__ |
#define | CKVP_DECL_END__ |
#define | CKVP_OUT_SIZE 511 |
#define | CKVP_OUT_SIZE_STR "511" |
#define | CKVP_INIT { CKVP_NONE, 1, 1, 0x0002, 0, "" } |
#define | CKVP_NONE 0 |
Possible states (previously defined in an enum, but C++ didn't like it) | |
#define | CKVP_OUT_FULL 1 |
Buffer "out" is full, must be flushed. | |
#define | CKVP_OUT_KEY 2 |
Everything stored until now is a key. | |
#define | CKVP_OUT_VALUE 3 |
Everything stored until now is a value. | |
#define | CKVP_ERROR 4 |
Error status, check line/column. |
Functions | |
size_t | ckvp_parse (ckvp_t *ckvp, size_t size, const char in[]) |
ckvp_parse() takes the current state (ckvp), a buffer in[size] and returns the number of characters processed. |
Simple parser for "key = value" text files, by zamaz.
Can also manage the following weird cases:
#define CKVP_DECL_BEGIN__ |
#define CKVP_DECL_END__ |
#define CKVP_ERROR 4 |
Error status, check line/column.
#define CKVP_INIT { CKVP_NONE, 1, 1, 0x0002, 0, "" } |
#define CKVP_NONE 0 |
Possible states (previously defined in an enum, but C++ didn't like it)
Nothing to report
#define CKVP_OUT_FULL 1 |
Buffer "out" is full, must be flushed.
#define CKVP_OUT_KEY 2 |
Everything stored until now is a key.
#define CKVP_OUT_SIZE 511 |
#define CKVP_OUT_SIZE_STR "511" |
#define CKVP_OUT_VALUE 3 |
Everything stored until now is a value.
size_t ckvp_parse | ( | ckvp_t * | ckvp, |
size_t | size, | ||
const char | in[] | ||
) |
ckvp_parse() takes the current state (ckvp), a buffer in[size] and returns the number of characters processed.
Each time ckvp_parse() returns, ckvp->state must be checked. If no error occured, ckvp_parse() must be called again with the remaining characters if any, otherwise the next input buffer.
At the end of input, ckvp_parse() must be called with a zero size.
This function doesn't allocate anything.
[in,out] | ckvp | Current state. |
size | Number of characters in buffer "in". | |
in | Input buffer to parse. |
State machine definition:
st[current_state][current_character] = next state | action
Special indices for current_character are: