Big cleanup

This commit is contained in:
eelke 2022-05-26 08:25:31 +02:00
parent d3080a08bb
commit 8b671090a0
55 changed files with 214 additions and 3967 deletions

View file

@ -25,17 +25,21 @@ ArrayParser::NextElemResult ArrayParser::GetNextElem()
{
// We should be at the start of an element or at the end of the array
NextElemResult result = { false, std::nullopt };
if (pos < end && *pos != ArrayEnd) {
if (*pos == Quote) {
if (pos < end && *pos != ArrayEnd)
{
if (*pos == Quote)
{
// parse quoted value, slow path removing escapes
parseQuotedValue();
result.ok = true;
result.value = std::string_view(temp);
}
else {
else
{
// parse unquoted value, fast path no escapes
const char *start = pos;
while (pos < end && *pos != Seperator && *pos != ArrayEnd) ++pos;
while (pos < end && *pos != Seperator && *pos != ArrayEnd)
++pos;
if (pos == end) // reached end of data shouldn't happen
throw std::runtime_error("Invalid input");
@ -47,7 +51,6 @@ ArrayParser::NextElemResult ArrayParser::GetNextElem()
// move to start of next element
++pos; // skip seperator
skipWhitespace();
}
return result;
}
@ -62,12 +65,15 @@ void ArrayParser::parseQuotedValue()
if (pos == end)
throw std::runtime_error("Invalid input");
while (pos < end) {
if (*pos == Quote) {
while (pos < end)
{
if (*pos == Quote)
{
++pos;
break;
}
if (*pos == '\\') {
if (*pos == '\\')
{
++pos;
if (pos == end)
throw std::runtime_error("Invalid input");
@ -84,9 +90,11 @@ void ArrayParser::initializeParse()
// Test if non empty string (empty string is an empty array)
//
skipWhitespace();
if (pos < end) {
if (pos < end)
{
// first character should be opening brace
if (*pos != ArrayStart) {
if (*pos != ArrayStart)
{
throw std::runtime_error("Unexpected input");
}
++pos;