17 class cNameValueParserTest
20 cNameValueParserTest(
void)
22 const char Data[] =
" Name1=Value1;Name2 = Value 2; Name3 =\"Value 3\"; Name4 =\'Value 4\'; Name5=\"Confusing; isn\'t it?\"";
26 for (
size_t i = 0; i <
sizeof(
Data) - 1; i++)
28 Parser2.
Parse(Data + i, 1);
38 for (cNameValueParser::const_iterator itr = Parser.begin(), end = Parser.end(); itr != end; ++itr)
40 ASSERT(Parser2[itr->first] == itr->second);
45 for (
int i = 0; i <
sizeof(
Data) - 2; i += 2)
47 Parser3.
Parse(Data + i, 2);
49 if ((
sizeof(Data) % 2) == 0)
51 Parser3.
Parse(Data +
sizeof(Data) - 2, 1);
56 for (cNameValueParser::const_iterator itr = Parser.begin(), end = Parser.end(); itr != end; ++itr)
58 ASSERT(Parser3[itr->first] == itr->second);
61 printf(
"cNameValueParserTest done");
76 m_AllowsKeyOnly(a_AllowsKeyOnly)
86 m_AllowsKeyOnly(a_AllowsKeyOnly)
88 Parse(a_Data, a_Size);
100 for (
size_t i = 0; i < a_Size;)
113 while ((i < a_Size) && (a_Data[i] <=
' '))
117 if ((i < a_Size) && (a_Data[i] >
' '))
130 if (a_Data[i] ==
'=')
138 else if (a_Data[i] <=
' ')
146 else if (a_Data[i] ==
';')
161 else if ((a_Data[i] ==
'\"') || (a_Data[i] ==
'\''))
182 if (a_Data[i] ==
'=')
189 else if (a_Data[i] ==
';')
204 else if (a_Data[i] >
' ')
219 if (a_Data[i] ==
';')
233 else if (a_Data[i] ==
'\"')
240 else if (a_Data[i] ==
'\'')
263 if (a_Data[i] ==
'\"')
287 if (a_Data[i] ==
'\'')
311 if (a_Data[i] ==
';')
336 if (a_Data[i] ==
';')
343 else if (a_Data[i] <
' ')
406 UNREACHABLE(
"Unsupported name value parser state");
bool Finish(void)
Notifies the parser that no more data will be coming.
eState m_State
The current state of the parser.
@ psValueInDQuotes
Just parsed a Double-quote sign after the Equal sign.
@ psEqual
Just parsed the = sign after a name.
@ psFinished
The parser has already been instructed to finish and doesn't expect any more data.
@ psInvalid
The parser has encountered an invalid input; further parsing is skipped.
@ psEqualSpace
Space after m_CurrentKey.
@ psAfterValue
Just finished parsing the value, waiting for semicolon or data end.
@ psKey
Currently adding more chars to the key in m_CurrentKey.
@ psValueRaw
Just parsed a raw value without a quote.
@ psKeySpace
Parsing the space in front of the next key.
@ psValueInSQuotes
Just parsed a Single-quote sign after the Equal sign.
bool m_AllowsKeyOnly
If true, the parser will accept keys without an equal sign and the value.
AString m_CurrentValue
Buffer for the current Value;.
cNameValueParser(bool a_AllowsKeyOnly=true)
Creates an empty parser.
AString m_CurrentKey
Buffer for the current Key.
void Parse(const char *a_Data, size_t a_Size)
Parses the data given.