From 2d1d176a5599fedc4d424cd5a784b002f24ff04d Mon Sep 17 00:00:00 2001 From: Antonio Cervone Date: Fri, 27 Nov 2015 16:31:43 +0100 Subject: [PATCH] add routine to detect c-style comments --- json11.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/json11.cpp b/json11.cpp index 0aa125b..e2085a1 100644 --- a/json11.cpp +++ b/json11.cpp @@ -364,6 +364,33 @@ struct JsonParser { i++; } + /* consume_comment() + * + * Advance comments (c-style inline and multiline). + */ + void consume_comment() { + if (str[i] == '/') { + i++; + if (str[i] == '/') { // inline comment + i++; + // advance until next line + while (str[i] != '\n') + i++; + consume_whitespace(); + consume_comment(); + } + else if (str[i] == '*') { // multiline comment + i++; + // advance until closing tokens + while (!(str[i] == '*' && str[i+1] == '/')) + i++; + i += 2; + consume_whitespace(); + consume_comment(); + } + } + } + /* get_next_token() * * Return the next non-whitespace character. If the end of the input is reached,