Add comment support in JSON.
This isn't strictly JSON compatible, but it is very useful. Implement
/**/ because it is pretty simple.
Change-Id: Ia277200e43d5a86a4e5ddcc0456c1e220e2b1d75
diff --git a/aos/json_to_flatbuffer_test.cc b/aos/json_to_flatbuffer_test.cc
index be752d0..7325c0c 100644
--- a/aos/json_to_flatbuffer_test.cc
+++ b/aos/json_to_flatbuffer_test.cc
@@ -144,6 +144,12 @@
EXPECT_TRUE(JsonAndBack("{ }"));
}
+// Tests that comments get stripped.
+TEST_F(JsonToFlatbufferTest, Comments) {
+ EXPECT_TRUE(JsonAndBack("{ /* foo */ \"vector_foo_double\": [ 9, 7, 1 ] }",
+ "{ \"vector_foo_double\": [ 9.0, 7.0, 1.0 ] }"));
+}
+
// Tests that multiple arrays get properly handled.
TEST_F(JsonToFlatbufferTest, MultipleArrays) {
EXPECT_TRUE(
diff --git a/aos/json_tokenizer.cc b/aos/json_tokenizer.cc
index 38ff4e3..78bf46e 100644
--- a/aos/json_tokenizer.cc
+++ b/aos/json_tokenizer.cc
@@ -13,6 +13,13 @@
} else if (Char() == '\n') {
ConsumeChar();
++linenumber_;
+ } else if (Consume("/*")) {
+ while (!Consume("*/")) {
+ if (Char() == '\n') {
+ ++linenumber_;
+ }
+ ConsumeChar();
+ }
} else {
// There is no fail. Once we are out of whitespace (including 0 of it),
// declare success.