Parse booleans

This commit is contained in:
Benoit Blanchon
2014-10-15 23:10:52 +02:00
parent 086d07151f
commit c61ee09d26
5 changed files with 43 additions and 9 deletions

View File

@ -60,6 +60,11 @@ bool JsonParser::isComma()
return *_ptr == ',';
}
bool JsonParser::isBoolean()
{
return *_ptr == 't' || *_ptr == 'f';
}
void JsonParser::skipOneChar()
{
_ptr++;
@ -83,6 +88,9 @@ JsonNode* JsonParser::parseAnything()
if (isDouble())
return parseDouble();
if (isBoolean())
return parseBoolean();
return 0;
}
@ -133,3 +141,14 @@ JsonNode *JsonParser::parseDouble()
return _buffer->createDoubleNode(value, decimals);
}
JsonNode *JsonParser::parseBoolean()
{
bool value = *_ptr == 't';
_ptr += value ? 4 : 5;
// 4 = strlen("true")
// 5 = strlen("false");
return _buffer->createBoolNode(value);
}