From 802ab2c7812dcf3b6cf0ceee490842236dc3083f Mon Sep 17 00:00:00 2001 From: Mikolaj Izdebski Date: Tue, 22 Jul 2025 12:36:15 +0200 Subject: [PATCH] Simplify character and string literal parsing logic Refactor and simplify parsing logic for character and string literals within find_token(). Merge redundant conditional branches, reduce unnecessary control flow, and replace multi-line loops with more concise equivalents. --- src/java_symbols.hpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/java_symbols.hpp b/src/java_symbols.hpp index 9028409..bdfcb56 100644 --- a/src/java_symbols.hpp +++ b/src/java_symbols.hpp @@ -257,7 +257,7 @@ inline std::ptrdiff_t find_token(std::string_view content, std::string_view toke { return position; } - else if (content[position] == '\'') + if (content[position] == '\'') { if (content.substr(position, 4) == "'\\''") { @@ -265,28 +265,15 @@ inline std::ptrdiff_t find_token(std::string_view content, std::string_view toke } else { - do - { - ++position; - } - while (position < std::ssize(content) and content[position] != '\''); + while (++position < std::ssize(content) and content[position] != '\''); } } else if (content[position] == '"') { - ++position; - - while (position < std::ssize(content) and content[position] != '"') + while (++position < std::ssize(content) and content[position] != '"') { - if (content.substr(position, 2) == "\\\\") - { - position += 2; - } - else if (content.substr(position, 2) == "\\\"") - { - position += 2; - } - else + auto substring = content.substr(position, 2); + if (substring == "\\\\" or substring == "\\\"") { ++position; }