| 482 | } |
| 483 | |
| 484 | void StyledWriter::writeArrayValue(const Value& value) { |
| 485 | unsigned size = value.size(); |
| 486 | if (size == 0) |
| 487 | pushValue("[]"); |
| 488 | else { |
| 489 | bool isArrayMultiLine = isMultilineArray(value); |
| 490 | if (isArrayMultiLine) { |
| 491 | writeWithIndent("["); |
| 492 | indent(); |
| 493 | bool hasChildValue = !childValues_.empty(); |
| 494 | unsigned index = 0; |
| 495 | for (;;) { |
| 496 | const Value& childValue = value[index]; |
| 497 | writeCommentBeforeValue(childValue); |
| 498 | if (hasChildValue) |
| 499 | writeWithIndent(childValues_[index]); |
| 500 | else { |
| 501 | writeIndent(); |
| 502 | writeValue(childValue); |
| 503 | } |
| 504 | if (++index == size) { |
| 505 | writeCommentAfterValueOnSameLine(childValue); |
| 506 | break; |
| 507 | } |
| 508 | document_ += ','; |
| 509 | writeCommentAfterValueOnSameLine(childValue); |
| 510 | } |
| 511 | unindent(); |
| 512 | writeWithIndent("]"); |
| 513 | } else // output on a single line |
| 514 | { |
| 515 | assert(childValues_.size() == size); |
| 516 | document_ += "[ "; |
| 517 | for (unsigned index = 0; index < size; ++index) { |
| 518 | if (index > 0) |
| 519 | document_ += ", "; |
| 520 | document_ += childValues_[index]; |
| 521 | } |
| 522 | document_ += " ]"; |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | bool StyledWriter::isMultilineArray(const Value& value) { |
| 528 | ArrayIndex const size = value.size(); |