@@ -720,7 +720,9 @@ int BuiltStyledStreamWriter::write(Value const& root)
720
720
indented_ = true ;
721
721
writeValue (root);
722
722
writeCommentAfterValueOnSameLine (root);
723
- sout_ << " \n " ;
723
+ if (!indentation_.empty ()) {
724
+ sout_ << " \n " ;
725
+ }
724
726
return 0 ;
725
727
}
726
728
void BuiltStyledStreamWriter::writeValue (Value const & value) {
@@ -759,7 +761,9 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
759
761
Value const & childValue = value[name];
760
762
writeCommentBeforeValue (childValue);
761
763
writeWithIndent (valueToQuotedString (name.c_str ()));
762
- sout_ << " : " ;
764
+ if (!indentation_.empty ()) sout_ << " " ;
765
+ sout_ << " :" ;
766
+ if (!indentation_.empty ()) sout_ << " " ;
763
767
writeValue (childValue);
764
768
if (++it == members.end ()) {
765
769
writeCommentAfterValueOnSameLine (childValue);
@@ -809,13 +813,15 @@ void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
809
813
} else // output on a single line
810
814
{
811
815
assert (childValues_.size () == size);
812
- sout_ << " [ " ;
816
+ sout_ << " [" ;
817
+ if (!indentation_.empty ()) sout_ << " " ;
813
818
for (unsigned index = 0 ; index < size; ++index) {
814
819
if (index > 0 )
815
820
sout_ << " , " ;
816
821
sout_ << childValues_[index];
817
822
}
818
- sout_ << " ]" ;
823
+ if (!indentation_.empty ()) sout_ << " " ;
824
+ sout_ << " ]" ;
819
825
}
820
826
}
821
827
}
@@ -860,7 +866,11 @@ void BuiltStyledStreamWriter::writeIndent() {
860
866
// to determine whether we are already indented, but
861
867
// with a stream we cannot do that. So we rely on some saved state.
862
868
// The caller checks indented_.
863
- sout_ << ' \n ' << indentString_;
869
+
870
+ if (!indentation_.empty ()) {
871
+ // In this case, drop newlines too.
872
+ sout_ << ' \n ' << indentString_;
873
+ }
864
874
}
865
875
866
876
void BuiltStyledStreamWriter::writeWithIndent (std::string const & value) {
@@ -877,6 +887,7 @@ void BuiltStyledStreamWriter::unindent() {
877
887
}
878
888
879
889
void BuiltStyledStreamWriter::writeCommentBeforeValue (Value const & root) {
890
+ if (cs_ == CommentStyle::None) return ;
880
891
if (!root.hasComment (commentBefore))
881
892
return ;
882
893
@@ -895,6 +906,7 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
895
906
}
896
907
897
908
void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine (Value const & root) {
909
+ if (cs_ == CommentStyle::None) return ;
898
910
if (root.hasComment (commentAfterOnSameLine))
899
911
sout_ << " " + root.getComment (commentAfterOnSameLine);
900
912
0 commit comments