From a7b8cc91ea74ebad894639a22816624b17202d9a Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 15 May 2025 17:39:07 -0400 Subject: [PATCH] Remove Parser2::parseLiteral --- src/test.cpp | 49 +++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/src/test.cpp b/src/test.cpp index 8a296b0..67d4363 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -472,17 +472,6 @@ private: ++buf; } } - Status parseLiteral(const char *literal) { - const int litLen = strlen(literal); - if (len() < litLen) { - return S_REJECT; - } - if (memcmp(buf, literal, litLen) == 0) { - buf += litLen; - return S_OK; - } - return S_REJECT; - } Status parse_number() { char *const bufBefore = buf; if (len() == 0 || !('0' <= *buf && *buf <= '9' || (*buf == '.'))) { @@ -509,10 +498,7 @@ private: } int stringLen = result - buf; callbacks->on_string_data(data, buf, stringLen); - buf += stringLen; - if (Status s = parseLiteral("\"")) { - return s; - } + buf += stringLen + 1; callbacks->on_end_string(data); return S_OK; } @@ -609,7 +595,8 @@ private: MUSTTAIL return keepGoing(self); } static Status arrayOrEnd(Parser2 *self) { - if (self->parseLiteral("]") == S_OK) { + if (*self->buf == ']') { + ++self->buf; self->pop(); self->callbacks->on_end_array(self->data); MUSTTAIL return keepGoing(self); @@ -622,11 +609,13 @@ private: } } static Status objectOrEnd(Parser2 *self) { - if (self->parseLiteral("}") == S_OK) { + if (*self->buf == '}') { + ++self->buf; self->pop(); self->callbacks->on_end_object(self->data); MUSTTAIL return keepGoing(self); - } else if (self->parseLiteral("\"") == S_OK) { + } else if (*self->buf == '"') { + ++self->buf; self->pop(); if (Status s = self->push( {N_STRING, T_COLON, N_VALUE, N_OBJECT_MAYBE_CONTINUE})) { @@ -637,13 +626,15 @@ private: return S_REJECT; } static Status arrayContinue(Parser2 *self) { - if (self->parseLiteral(",") == S_OK) { + if (*self->buf == ',') { + ++self->buf; self->pop(); if (Status s = self->push({N_VALUE, N_ARRAY_MAYBE_CONTINUE})) { return s; } MUSTTAIL return keepGoing(self); - } else if (self->parseLiteral("]") == S_OK) { + } else if (*self->buf == ']') { + ++self->buf; self->pop(); self->callbacks->on_end_array(self->data); MUSTTAIL return keepGoing(self); @@ -651,27 +642,22 @@ private: return S_REJECT; } static Status objectContinue(Parser2 *self) { - if (self->parseLiteral(",") == S_OK) { + if (*self->buf == ',') { + ++self->buf; self->pop(); if (Status s = self->push({T_DUBQUOTE, N_STRING, T_COLON, N_VALUE, N_OBJECT_MAYBE_CONTINUE})) { return s; } MUSTTAIL return keepGoing(self); - } else if (self->parseLiteral("}") == S_OK) { + } else if (*self->buf == '}') { + ++self->buf; self->pop(); self->callbacks->on_end_object(self->data); MUSTTAIL return keepGoing(self); } return S_REJECT; } - static Status colon(Parser2 *self) { - if (*self->buf++ == ':') { - self->pop(); - MUSTTAIL return keepGoing(self); - } - return S_REJECT; - } static Status finishTrue(Parser2 *self) { if (*self->buf++ == 'e') { self->pop(); @@ -697,8 +683,7 @@ private: return S_REJECT; } template static Status singleChar(Parser2 *self) { - if (*self->buf == kChar) { - ++self->buf; + if (*self->buf++ == kChar) { self->pop(); MUSTTAIL return keepGoing(self); } @@ -706,7 +691,7 @@ private: } static constexpr continuation table[N_PAST_END] = { - /*T_COLON*/ colon, + /*T_COLON*/ singleChar<':'>, /*T_TRUE*/ finishTrue, /*T_FALSE*/ finishFalse, /*T_NULL*/ finishNull,