mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-07 01:04:55 +02:00
implement CommentStyle::None/indentation_==""
This commit is contained in:
parent
1e21e63853
commit
c6e0688e5a
@ -720,7 +720,9 @@ int BuiltStyledStreamWriter::write(Value const& root)
|
|||||||
indented_ = true;
|
indented_ = true;
|
||||||
writeValue(root);
|
writeValue(root);
|
||||||
writeCommentAfterValueOnSameLine(root);
|
writeCommentAfterValueOnSameLine(root);
|
||||||
sout_ << "\n";
|
if (!indentation_.empty()) {
|
||||||
|
sout_ << "\n";
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void BuiltStyledStreamWriter::writeValue(Value const& value) {
|
void BuiltStyledStreamWriter::writeValue(Value const& value) {
|
||||||
@ -759,7 +761,9 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
|
|||||||
Value const& childValue = value[name];
|
Value const& childValue = value[name];
|
||||||
writeCommentBeforeValue(childValue);
|
writeCommentBeforeValue(childValue);
|
||||||
writeWithIndent(valueToQuotedString(name.c_str()));
|
writeWithIndent(valueToQuotedString(name.c_str()));
|
||||||
sout_ << " : ";
|
if (!indentation_.empty()) sout_ << " ";
|
||||||
|
sout_ << ":";
|
||||||
|
if (!indentation_.empty()) sout_ << " ";
|
||||||
writeValue(childValue);
|
writeValue(childValue);
|
||||||
if (++it == members.end()) {
|
if (++it == members.end()) {
|
||||||
writeCommentAfterValueOnSameLine(childValue);
|
writeCommentAfterValueOnSameLine(childValue);
|
||||||
@ -809,13 +813,15 @@ void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
|
|||||||
} else // output on a single line
|
} else // output on a single line
|
||||||
{
|
{
|
||||||
assert(childValues_.size() == size);
|
assert(childValues_.size() == size);
|
||||||
sout_ << "[ ";
|
sout_ << "[";
|
||||||
|
if (!indentation_.empty()) sout_ << " ";
|
||||||
for (unsigned index = 0; index < size; ++index) {
|
for (unsigned index = 0; index < size; ++index) {
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
sout_ << ", ";
|
sout_ << ", ";
|
||||||
sout_ << childValues_[index];
|
sout_ << childValues_[index];
|
||||||
}
|
}
|
||||||
sout_ << " ]";
|
if (!indentation_.empty()) sout_ << " ";
|
||||||
|
sout_ << "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -860,7 +866,11 @@ void BuiltStyledStreamWriter::writeIndent() {
|
|||||||
// to determine whether we are already indented, but
|
// to determine whether we are already indented, but
|
||||||
// with a stream we cannot do that. So we rely on some saved state.
|
// with a stream we cannot do that. So we rely on some saved state.
|
||||||
// The caller checks indented_.
|
// The caller checks indented_.
|
||||||
sout_ << '\n' << indentString_;
|
|
||||||
|
if (!indentation_.empty()) {
|
||||||
|
// In this case, drop newlines too.
|
||||||
|
sout_ << '\n' << indentString_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuiltStyledStreamWriter::writeWithIndent(std::string const& value) {
|
void BuiltStyledStreamWriter::writeWithIndent(std::string const& value) {
|
||||||
@ -877,6 +887,7 @@ void BuiltStyledStreamWriter::unindent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
|
void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
|
||||||
|
if (cs_ == CommentStyle::None) return;
|
||||||
if (!root.hasComment(commentBefore))
|
if (!root.hasComment(commentBefore))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -895,6 +906,7 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine(Value const& root) {
|
void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine(Value const& root) {
|
||||||
|
if (cs_ == CommentStyle::None) return;
|
||||||
if (root.hasComment(commentAfterOnSameLine))
|
if (root.hasComment(commentAfterOnSameLine))
|
||||||
sout_ << " " + root.getComment(commentAfterOnSameLine);
|
sout_ << " " + root.getComment(commentAfterOnSameLine);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user