| 545 | } |
| 546 | |
| 547 | bool StyledWriter::isMultilineArray(const Value& value) { |
| 548 | ArrayIndex const size = value.size(); |
| 549 | bool isMultiLine = size * 3 >= rightMargin_; |
| 550 | childValues_.clear(); |
| 551 | for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) { |
| 552 | const Value& childValue = value[index]; |
| 553 | isMultiLine = ((childValue.isArray() || childValue.isObject()) && |
| 554 | !childValue.empty()); |
| 555 | } |
| 556 | if (!isMultiLine) // check if line length > max line length |
| 557 | { |
| 558 | childValues_.reserve(size); |
| 559 | addChildValues_ = true; |
| 560 | ArrayIndex lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' |
| 561 | for (ArrayIndex index = 0; index < size; ++index) { |
| 562 | if (hasCommentForValue(value[index])) { |
| 563 | isMultiLine = true; |
| 564 | } |
| 565 | writeValue(value[index]); |
| 566 | lineLength += static_cast<ArrayIndex>(childValues_[index].length()); |
| 567 | } |
| 568 | addChildValues_ = false; |
| 569 | isMultiLine = isMultiLine || lineLength >= rightMargin_; |
| 570 | } |
| 571 | return isMultiLine; |
| 572 | } |
| 573 | |
| 574 | void StyledWriter::pushValue(const JSONCPP_STRING& value) { |
| 575 | if (addChildValues_) |