MCPcopy Create free account
hub / github.com/Kitware/CMake / writeArrayValue

Method writeArrayValue

Utilities/cmjsoncpp/src/lib_json/json_writer.cpp:515–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

513}
514
515void StyledWriter::writeArrayValue(const Value& value) {
516 size_t size = value.size();
517 if (size == 0)
518 pushValue("[]");
519 else {
520 bool isArrayMultiLine = isMultilineArray(value);
521 if (isArrayMultiLine) {
522 writeWithIndent("[");
523 indent();
524 bool hasChildValue = !childValues_.empty();
525 ArrayIndex index = 0;
526 for (;;) {
527 const Value& childValue = value[index];
528 writeCommentBeforeValue(childValue);
529 if (hasChildValue)
530 writeWithIndent(childValues_[index]);
531 else {
532 writeIndent();
533 writeValue(childValue);
534 }
535 if (++index == size) {
536 writeCommentAfterValueOnSameLine(childValue);
537 break;
538 }
539 document_ += ',';
540 writeCommentAfterValueOnSameLine(childValue);
541 }
542 unindent();
543 writeWithIndent("]");
544 } else // output on a single line
545 {
546 assert(childValues_.size() == size);
547 document_ += "[ ";
548 for (size_t index = 0; index < size; ++index) {
549 if (index > 0)
550 document_ += ", ";
551 document_ += childValues_[index];
552 }
553 document_ += " ]";
554 }
555 }
556}
557
558bool StyledWriter::isMultilineArray(const Value& value) {
559 ArrayIndex const size = value.size();

Callers

nothing calls this directly

Calls 2

sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected