Skip to content

Commit 201904b

Browse files
committed
Merge pull request open-source-parsers#138 from cdunn2001/fix-103
Fix open-source-parsers#103.
2 parents 9fbd12b + 216ecd3 commit 201904b

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/lib_json/json_writer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ bool StyledWriter::isMultineArray(const Value& value) {
376376
addChildValues_ = true;
377377
int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
378378
for (int index = 0; index < size; ++index) {
379+
if (hasCommentForValue(value[index])) {
380+
isMultiLine = true;
381+
}
379382
writeValue(value[index]);
380383
lineLength += int(childValues_[index].length());
381384
}
@@ -584,6 +587,9 @@ bool StyledStreamWriter::isMultineArray(const Value& value) {
584587
addChildValues_ = true;
585588
int lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]'
586589
for (int index = 0; index < size; ++index) {
590+
if (hasCommentForValue(value[index])) {
591+
isMultiLine = true;
592+
}
587593
writeValue(value[index]);
588594
lineLength += int(childValues_[index].length());
589595
}

test/data/test_comment_00.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Comment for array
2+
.=[]
3+
// Comment within array
4+
.[0]="one-element"

test/data/test_comment_00.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Comment for array
2+
[
3+
// Comment within array
4+
"one-element"
5+
]

0 commit comments

Comments
 (0)