diff --git a/include/nlohmann/detail/input/lexer.hpp b/include/nlohmann/detail/input/lexer.hpp index 0219fb8d1..61553c01c 100644 --- a/include/nlohmann/detail/input/lexer.hpp +++ b/include/nlohmann/detail/input/lexer.hpp @@ -1194,35 +1194,43 @@ scan_number_done: while (current == ' ' or current == '\t' or current == '\n' or current == '\r'); #else // skip white space and comments if comment stripping enabled - while(true) { - // first skip any whitespace - do { - get(); - } - while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); - - // next, skip any comment - if(current == '/') { - get(); - // really a comment? - if (current == '/') { - // skip to the end of line/file - do { + while (true) + { + // first skip any whitespace + do + { get(); - } while (! (current == '\n' || - current == '\r' || - current == std::char_traits::eof())); } - else { - // not a comment, leave it up to the rest of the code to deal with the '/' - unget(); - break; + while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); + + // next, skip any comment + if (current == '/') + { + get(); + // really a comment? + if (current == '/') + { + // skip to the end of line/file + do + { + get(); + } + while (! (current == '\n' || + current == '\r' || + current == std::char_traits::eof())); + } + else + { + // not a comment, leave it up to the rest of the code to deal with the '/' + unget(); + break; + } + } + else + { + // not a comment at all, break out of the loop + break; } - } - else { - // not a comment at all, break out of the loop - break; - } } #endif diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 6b6655af8..3e90a4841 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3024,12 +3024,54 @@ scan_number_done: token_type scan() { +#ifndef JSON_STRIP_COMMENTS // read next character and ignore whitespace do { get(); } while (current == ' ' or current == '\t' or current == '\n' or current == '\r'); +#else + // skip white space and comments if comment stripping enabled + while (true) + { + // first skip any whitespace + do + { + get(); + } + while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); + + // next, skip any comment + if (current == '/') + { + get(); + // really a comment? + if (current == '/') + { + // skip to the end of line/file + do + { + get(); + } + while (! (current == '\n' || + current == '\r' || + current == std::char_traits::eof())); + } + else + { + // not a comment, leave it up to the rest of the code to deal with the '/' + unget(); + break; + } + } + else + { + // not a comment at all, break out of the loop + break; + } + } +#endif switch (current) {