| 525 | } |
| 526 | |
| 527 | bool StyledWriter::isMultilineArray(const Value& value) { |
| 528 | ArrayIndex const size = value.size(); |
| 529 | bool isMultiLine = size * 3 >= rightMargin_; |
| 530 | childValues_.clear(); |
| 531 | for (ArrayIndex index = 0; index < size && !isMultiLine; ++index) { |
| 532 | const Value& childValue = value[index]; |
| 533 | isMultiLine = ((childValue.isArray() || childValue.isObject()) && |
| 534 | childValue.size() > 0); |
| 535 | } |
| 536 | if (!isMultiLine) // check if line length > max line length |
| 537 | { |
| 538 | childValues_.reserve(size); |
| 539 | addChildValues_ = true; |
| 540 | ArrayIndex lineLength = 4 + (size - 1) * 2; // '[ ' + ', '*n + ' ]' |
| 541 | for (ArrayIndex index = 0; index < size; ++index) { |
| 542 | if (hasCommentForValue(value[index])) { |
| 543 | isMultiLine = true; |
| 544 | } |
| 545 | writeValue(value[index]); |
| 546 | lineLength += static_cast<ArrayIndex>(childValues_[index].length()); |
| 547 | } |
| 548 | addChildValues_ = false; |
| 549 | isMultiLine = isMultiLine || lineLength >= rightMargin_; |
| 550 | } |
| 551 | return isMultiLine; |
| 552 | } |
| 553 | |
| 554 | void StyledWriter::pushValue(const JSONCPP_STRING& value) { |
| 555 | if (addChildValues_) |