detect multiple comments with a loop instead of using recursion
parent
882feb56ac
commit
b05e655c0a
18
json11.cpp
18
json11.cpp
|
@ -369,7 +369,8 @@ struct JsonParser {
|
||||||
*
|
*
|
||||||
* Advance comments (c-style inline and multiline).
|
* Advance comments (c-style inline and multiline).
|
||||||
*/
|
*/
|
||||||
void consume_comment() {
|
bool consume_comment() {
|
||||||
|
bool comment_found = false;
|
||||||
if (str[i] == '/') {
|
if (str[i] == '/') {
|
||||||
i++;
|
i++;
|
||||||
if (str[i] == '/') { // inline comment
|
if (str[i] == '/') { // inline comment
|
||||||
|
@ -377,8 +378,7 @@ struct JsonParser {
|
||||||
// advance until next line
|
// advance until next line
|
||||||
while (str[i] != '\n')
|
while (str[i] != '\n')
|
||||||
i++;
|
i++;
|
||||||
consume_whitespace();
|
comment_found = true;
|
||||||
consume_comment();
|
|
||||||
}
|
}
|
||||||
else if (str[i] == '*') { // multiline comment
|
else if (str[i] == '*') { // multiline comment
|
||||||
i++;
|
i++;
|
||||||
|
@ -386,10 +386,10 @@ struct JsonParser {
|
||||||
while (!(str[i] == '*' && str[i+1] == '/'))
|
while (!(str[i] == '*' && str[i+1] == '/'))
|
||||||
i++;
|
i++;
|
||||||
i += 2;
|
i += 2;
|
||||||
consume_whitespace();
|
comment_found = true;
|
||||||
consume_comment();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return comment_found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* consume_garbage()
|
/* consume_garbage()
|
||||||
|
@ -399,8 +399,12 @@ struct JsonParser {
|
||||||
void consume_garbage() {
|
void consume_garbage() {
|
||||||
consume_whitespace();
|
consume_whitespace();
|
||||||
if(detect_comments) {
|
if(detect_comments) {
|
||||||
consume_comment();
|
bool comment_found = false;
|
||||||
consume_whitespace();
|
do {
|
||||||
|
comment_found = consume_comment();
|
||||||
|
consume_whitespace();
|
||||||
|
}
|
||||||
|
while(comment_found);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue