| 4601 | } |
| 4602 | |
| 4603 | void StyledWriter::writeArrayValue(const Value& value) { |
| 4604 | size_t size = value.size(); |
| 4605 | if (size == 0) |
| 4606 | pushValue("[]"); |
| 4607 | else { |
| 4608 | bool isArrayMultiLine = isMultilineArray(value); |
| 4609 | if (isArrayMultiLine) { |
| 4610 | writeWithIndent("["); |
| 4611 | indent(); |
| 4612 | bool hasChildValue = !childValues_.empty(); |
| 4613 | ArrayIndex index = 0; |
| 4614 | for (;;) { |
| 4615 | const Value& childValue = value[index]; |
| 4616 | writeCommentBeforeValue(childValue); |
| 4617 | if (hasChildValue) |
| 4618 | writeWithIndent(childValues_[index]); |
| 4619 | else { |
| 4620 | writeIndent(); |
| 4621 | writeValue(childValue); |
| 4622 | } |
| 4623 | if (++index == size) { |
| 4624 | writeCommentAfterValueOnSameLine(childValue); |
| 4625 | break; |
| 4626 | } |
| 4627 | document_ += ','; |
| 4628 | writeCommentAfterValueOnSameLine(childValue); |
| 4629 | } |
| 4630 | unindent(); |
| 4631 | writeWithIndent("]"); |
| 4632 | } else // output on a single line |
| 4633 | { |
| 4634 | assert(childValues_.size() == size); |
| 4635 | document_ += "[ "; |
| 4636 | for (size_t index = 0; index < size; ++index) { |
| 4637 | if (index > 0) |
| 4638 | document_ += ", "; |
| 4639 | document_ += childValues_[index]; |
| 4640 | } |
| 4641 | document_ += " ]"; |
| 4642 | } |
| 4643 | } |
| 4644 | } |
| 4645 | |
| 4646 | bool StyledWriter::isMultilineArray(const Value& value) { |
| 4647 | ArrayIndex const size = value.size(); |