Parser to fill a KeyValuesData
structure out of a character buffer.
More...
#include <KeyValueParser.h>
Classes | |
struct | FormatParams_t |
Parameters of the format. More... | |
struct | ParserError |
Public Types | |
using | Error = icarus::KeyValuesData::Error |
Base of all errors by KeyValueParser. More... | |
using | ParsedData_t = icarus::KeyValuesData |
Type of returned data. More... | |
Public Member Functions | |
KeyValueParser (FormatParams_t formatParams=DefaultFormatParameters, icarus::ParsingToolkit::Params_t parserParams=icarus::ParsingToolkit::DefaultParameters) | |
Creates a parser with the specified parsing parameters. More... | |
ParsedData_t | parse (std::string const &s) const |
Runs the parser on a string. More... | |
ParsedData_t | parse (std::istream &stream) const |
Parses the stream and returns a data structure with the content. More... | |
ParsedData_t | parse (std::istream &&stream) const |
ParsedData_t | operator() (std::istream &stream) const |
Static Public Attributes | |
static const FormatParams_t | DefaultFormatParameters |
Private Types | |
enum | keyType { keyType::unsupported, keyType::create, keyType::add } |
Private Member Functions | |
keyType | highlightSeparator (std::vector< std::string_view > &tokens) const |
Modifies tokens placing the key/value separator in its own token. More... | |
template<typename Key > | |
keyType | keySepType (Key const &key) const |
Returns the type of key . More... | |
Private Attributes | |
icarus::ParsingToolkit | fPTK |
Parsing toolkit (and its parameters). More... | |
FormatParams_t | fFmt |
Parser format parameters. More... | |
std::vector< std::string > | fKeys |
Sorted keys cache. More... | |
Parser to fill a KeyValuesData
structure out of a character buffer.
The parser processes an input stream or string. Parsing produces a data structure of type icarus::KeyValuesData
; it is not possible to reconstruct the input from that structure, since quotations, escapes, formatting and comments are lost.
The supported format is:
:
to create/overwrite, :+
to create/append values)#
and extend to the end of the lineThis is the text from the unit test:
Definition at line 73 of file KeyValueParser.h.
Base of all errors by KeyValueParser.
Definition at line 78 of file KeyValueParser.h.
Type of returned data.
Definition at line 81 of file KeyValueParser.h.
|
strongprivate |
Enumerator | |
---|---|
unsupported | |
create | |
add |
Definition at line 113 of file KeyValueParser.h.
icarus::details::KeyValueParser::KeyValueParser | ( | FormatParams_t | formatParams = DefaultFormatParameters , |
icarus::ParsingToolkit::Params_t | parserParams = icarus::ParsingToolkit::DefaultParameters |
||
) |
Creates a parser with the specified parsing parameters.
Definition at line 56 of file KeyValueParser.cxx.
|
private |
Modifies tokens
placing the key/value separator in its own token.
[in,out] | tokens | list of tokens |
On success, the first token is the key, the second the separator that was found, and the rest are values. The list of tokens
is modified in place. In case of failure, where the separator is not found where expected, tokens
are unchanged.
The separator is expected to be either unquoted and unescaped in the first of the tokens, or otherwise at the beginning of the second token.
|
private |
Returns the type of key
.
|
inline |
Definition at line 104 of file KeyValueParser.h.
ParsedData_t icarus::details::KeyValueParser::parse | ( | std::istream & | stream | ) | const |
Parses the stream
and returns a data structure with the content.
|
inline |
Definition at line 102 of file KeyValueParser.h.
ParsedData_t icarus::details::KeyValueParser::parse | ( | std::string const & | s | ) | const |
Runs the parser on a string.
|
static |
Definition at line 89 of file KeyValueParser.h.
|
private |
Parser format parameters.
Definition at line 116 of file KeyValueParser.h.
|
private |
Sorted keys cache.
Definition at line 118 of file KeyValueParser.h.
|
private |
Parsing toolkit (and its parameters).
Definition at line 115 of file KeyValueParser.h.