diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 00af0ce2..eab64f40 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -835,62 +835,54 @@ class lexer : public lexer_base */ bool scan_comment() { - // remember character after '/' to distinguish comment types - const auto comment_char = get(); - - // expect // or /* to start a comment - if (comment_char != '/' and comment_char != '*') + switch (get()) { - return false; - } - - while (true) - { - switch (get()) + case '/': { - // EOF inside a /* comment is an error, in // it is OK - case std::char_traits::eof(): - case '\0': + while (true) { - return comment_char == '/'; - } - - // a newline ends the // comment - case '\n': - case '\r': - { - if (comment_char == '/') + switch (get()) { - return true; + case '\n': + case '\r': + return true; + + default: + break; } - break; } + } - // */ ends the /* comment - case '*': + case '*': + { + while (true) { - if (comment_char == '*') + switch (get()) { - switch (get()) - { - case '/': - { - return true; - } + case std::char_traits::eof(): + case '\0': + return false; - default: + case '*': + { + switch (get()) { - unget(); - break; + case '/': + return true; + + default: + { + unget(); + break; + } } } } - break; } - - default: - break; } + + default: + return false; } } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 82435fa7..bdd97a14 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -8902,62 +8902,54 @@ class lexer : public lexer_base */ bool scan_comment() { - // remember character after '/' to distinguish comment types - const auto comment_char = get(); - - // expect // or /* to start a comment - if (comment_char != '/' and comment_char != '*') + switch (get()) { - return false; - } - - while (true) - { - switch (get()) + case '/': { - // EOF inside a /* comment is an error, in // it is OK - case std::char_traits::eof(): - case '\0': + while (true) { - return comment_char == '/'; - } - - // a newline ends the // comment - case '\n': - case '\r': - { - if (comment_char == '/') + switch (get()) { - return true; + case '\n': + case '\r': + return true; + + default: + break; } - break; } + } - // */ ends the /* comment - case '*': + case '*': + { + while (true) { - if (comment_char == '*') + switch (get()) { - switch (get()) - { - case '/': - { - return true; - } + case std::char_traits::eof(): + case '\0': + return false; - default: + case '*': + { + switch (get()) { - unget(); - break; + case '/': + return true; + + default: + { + unget(); + break; + } } } } - break; } - - default: - break; } + + default: + return false; } }