From ad137576a89c8ec30c5cbf349f62d6cd85ed4cac Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 12 Jul 2022 11:17:34 +0200 Subject: [PATCH] Util: Make character breaks in Lexer more clear syntactically --- src/util/json/lexer.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/util/json/lexer.cpp b/src/util/json/lexer.cpp index 59f15bf..717e1df 100644 --- a/src/util/json/lexer.cpp +++ b/src/util/json/lexer.cpp @@ -158,9 +158,7 @@ bool Lexer::getString() { size_t column = m_column; std::string symbol = ""; - - // Break on "\r\n - std::string breakOnGrammar = std::string("\"") + '\r' + '\n' + '\0'; + std::string breakOnCharacter = std::string() + '"' + '\r' + '\n' + '\0'; bool escape = false; char character = consume(); @@ -174,7 +172,7 @@ bool Lexer::getString() continue; } - if (!escape && breakOnGrammar.find(character) != std::string::npos) { + if (!escape && breakOnCharacter.find(character) != std::string::npos) { break; } @@ -200,13 +198,12 @@ bool Lexer::getNumberOrLiteral(Token::Type type) { size_t column = m_column; std::string symbol = ""; - std::string breakOnGrammar = std::string("{}[]:,\" ") + '\t' + '\r' + '\n' + '\0'; + std::string breakOnCharacter = std::string("{}[]:,") + '"' + ' ' + '\t' + '\r' + '\n' + '\0'; for (char character;;) { character = peek(); - // Break on all valid JSON grammar thats not a number or literal - if (breakOnGrammar.find(character) != std::string::npos) { + if (breakOnCharacter.find(character) != std::string::npos) { break; }