Skip to content

Commit bc8b5d8

Browse files
committed
Merge pull request open-source-parsers#52 from cquammen/master
Removed unneeded newlines from parsed comments
2 parents aa650c5 + fd06bfc commit bc8b5d8

23 files changed

+51
-3
lines changed

src/jsontestrunner/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ static std::string readInputTestFile(const char* path) {
6161

6262
static void
6363
printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
64+
if (value.hasComment(Json::commentBefore)) {
65+
fprintf(fout, "%s\n", value.getComment(Json::commentBefore).c_str());
66+
}
6467
switch (value.type()) {
6568
case Json::nullValue:
6669
fprintf(fout, "%s=null\n", path.c_str());
@@ -117,6 +120,10 @@ printValueTree(FILE* fout, Json::Value& value, const std::string& path = ".") {
117120
default:
118121
break;
119122
}
123+
124+
if (value.hasComment(Json::commentAfter)) {
125+
fprintf(fout, "%s\n", value.getComment(Json::commentAfter).c_str());
126+
}
120127
}
121128

122129
static int parseAndSaveValueTree(const std::string& input,

src/lib_json/json_reader.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,6 @@ Reader::addComment(Location begin, Location end, CommentPlacement placement) {
358358
assert(lastValue_ != 0);
359359
lastValue_->setComment(std::string(begin, end), placement);
360360
} else {
361-
if (!commentsBefore_.empty())
362-
commentsBefore_ += "\n";
363361
commentsBefore_ += std::string(begin, end);
364362
}
365363
}

test/data/test_basic_08.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// C++ style comment
12
.=null
23

test/data/test_basic_09.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
/* C style comment
2+
*/
13
.=null
24

test/data/test_comment_02.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
.={}
2+
/* C-style comment
3+
4+
C-style-2 comment */
25
.c-test={}
36
.c-test.a=1
7+
/* Internal comment c-style */
48
.c-test.b=2
9+
// C++-style comment
510
.cpp-test={}
11+
// Multiline comment cpp-style
12+
// Second line
613
.cpp-test.c=3
714
.cpp-test.d=4

test/data/test_comment_02.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
// C++-style comment
1111
"cpp-test" : {
12-
// Internal comment cpp-style
12+
// Multiline comment cpp-style
13+
// Second line
1314
"c" : 3,
1415
"d" : 4
1516
}

test/data/test_integer_01.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Max signed integer
12
.=2147483647

test/data/test_integer_02.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Min signed integer
12
.=-2147483648

test/data/test_integer_03.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// Max unsigned integer
12
.=4294967295

test/data/test_integer_04.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// Min unsigned integer
12
.=0
23

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/* A comment
2+
at the beginning of the file.
3+
*/
14
.={}
25
.first=1
6+
/* Comment before 'second'
7+
*/
38
.second=2
9+
/* A comment at
10+
the end of the file.
11+
*/

test/data/test_real_01.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// 2^33 => out of integer range, switch to double
12
.=8589934592
23

test/data/test_real_02.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// -2^32 => out of signed integer range, switch to double
12
.=-4294967295
23

test/data/test_real_03.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// -2^32 => out of signed integer range, switch to double
12
.=-4294967295
23

test/data/test_real_04.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
// 1.2345678
12
.=1.2345678
23

test/data/test_real_05.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// 1234567.8
12
.=1234567.8
23

34

test/data/test_real_06.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// -1.2345678
12
.=-1.2345678
23

34

test/data/test_real_07.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// -1234567.8
12
.=-1234567.8
23

34

test/data/test_real_08.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// Out of 32-bit integer range, switch to double in 32-bit mode. Length the
2+
// same as UINT_MAX in base 10 and digit less than UINT_MAX's last digit in
3+
// order to catch a bug in the parsing code.
14
.=4300000001

test/data/test_real_09.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// Out of 64-bit integer range, switch to double in all modes. Length the same
2+
// as ULONG_MAX in base 10 and digit less than ULONG_MAX's last digit in order
3+
// to catch a bug in the parsing code.
14
.=1.9e+19

test/data/test_real_10.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// Out of 32-bit signed integer range, switch to double in all modes. Length
2+
// the same as INT_MIN in base 10 and digit less than INT_MIN's last digit in
3+
// order to catch a bug in the parsing code.
14
.=-2200000001

test/data/test_real_11.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
// Out of 64-bit signed integer range, switch to double in all modes. Length
2+
// the same as LONG_MIN in base 10 and digit less than LONG_MIN's last digit in
3+
// order to catch a bug in the parsing code.
14
.=-9.3e+18

test/data/test_real_12.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// 2^64 -> switch to double.
12
.=1.844674407370955e+19

0 commit comments

Comments
 (0)