| 502 | } |
| 503 | |
| 504 | void StyledWriter::writeArrayValue(const Value& value) { |
| 505 | unsigned size = value.size(); |
| 506 | if (size == 0) |
| 507 | pushValue("[]"); |
| 508 | else { |
| 509 | bool isArrayMultiLine = isMultilineArray(value); |
| 510 | if (isArrayMultiLine) { |
| 511 | writeWithIndent("["); |
| 512 | indent(); |
| 513 | bool hasChildValue = !childValues_.empty(); |
| 514 | unsigned index = 0; |
| 515 | for (;;) { |
| 516 | const Value& childValue = value[index]; |
| 517 | writeCommentBeforeValue(childValue); |
| 518 | if (hasChildValue) |
| 519 | writeWithIndent(childValues_[index]); |
| 520 | else { |
| 521 | writeIndent(); |
| 522 | writeValue(childValue); |
| 523 | } |
| 524 | if (++index == size) { |
| 525 | writeCommentAfterValueOnSameLine(childValue); |
| 526 | break; |
| 527 | } |
| 528 | document_ += ','; |
| 529 | writeCommentAfterValueOnSameLine(childValue); |
| 530 | } |
| 531 | unindent(); |
| 532 | writeWithIndent("]"); |
| 533 | } else // output on a single line |
| 534 | { |
| 535 | assert(childValues_.size() == size); |
| 536 | document_ += "[ "; |
| 537 | for (unsigned index = 0; index < size; ++index) { |
| 538 | if (index > 0) |
| 539 | document_ += ", "; |
| 540 | document_ += childValues_[index]; |
| 541 | } |
| 542 | document_ += " ]"; |
| 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | bool StyledWriter::isMultilineArray(const Value& value) { |
| 548 | ArrayIndex const size = value.size(); |