@@ -720,7 +720,9 @@ int BuiltStyledStreamWriter::write(Value const& root)
720720 indented_ = true ;
721721 writeValue (root);
722722 writeCommentAfterValueOnSameLine (root);
723- sout_ << " \n " ;
723+ if (!indentation_.empty ()) {
724+ sout_ << " \n " ;
725+ }
724726 return 0 ;
725727}
726728void BuiltStyledStreamWriter::writeValue (Value const & value) {
@@ -759,7 +761,9 @@ void BuiltStyledStreamWriter::writeValue(Value const& value) {
759761 Value const & childValue = value[name];
760762 writeCommentBeforeValue (childValue);
761763 writeWithIndent (valueToQuotedString (name.c_str ()));
762- sout_ << " : " ;
764+ if (!indentation_.empty ()) sout_ << " " ;
765+ sout_ << " :" ;
766+ if (!indentation_.empty ()) sout_ << " " ;
763767 writeValue (childValue);
764768 if (++it == members.end ()) {
765769 writeCommentAfterValueOnSameLine (childValue);
@@ -809,13 +813,15 @@ void BuiltStyledStreamWriter::writeArrayValue(Value const& value) {
809813 } else // output on a single line
810814 {
811815 assert (childValues_.size () == size);
812- sout_ << " [ " ;
816+ sout_ << " [" ;
817+ if (!indentation_.empty ()) sout_ << " " ;
813818 for (unsigned index = 0 ; index < size; ++index) {
814819 if (index > 0 )
815820 sout_ << " , " ;
816821 sout_ << childValues_[index];
817822 }
818- sout_ << " ]" ;
823+ if (!indentation_.empty ()) sout_ << " " ;
824+ sout_ << " ]" ;
819825 }
820826 }
821827}
@@ -860,7 +866,11 @@ void BuiltStyledStreamWriter::writeIndent() {
860866 // to determine whether we are already indented, but
861867 // with a stream we cannot do that. So we rely on some saved state.
862868 // 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+ }
864874}
865875
866876void BuiltStyledStreamWriter::writeWithIndent (std::string const & value) {
@@ -877,6 +887,7 @@ void BuiltStyledStreamWriter::unindent() {
877887}
878888
879889void BuiltStyledStreamWriter::writeCommentBeforeValue (Value const & root) {
890+ if (cs_ == CommentStyle::None) return ;
880891 if (!root.hasComment (commentBefore))
881892 return ;
882893
@@ -895,6 +906,7 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
895906}
896907
897908void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine (Value const & root) {
909+ if (cs_ == CommentStyle::None) return ;
898910 if (root.hasComment (commentAfterOnSameLine))
899911 sout_ << " " + root.getComment (commentAfterOnSameLine);
900912
0 commit comments