File tree Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Expand file tree Collapse file tree 1 file changed +7
-9
lines changed Original file line number Diff line number Diff line change @@ -713,9 +713,11 @@ BuiltStyledStreamWriter::BuiltStyledStreamWriter(
713
713
int BuiltStyledStreamWriter::write (Value const & root)
714
714
{
715
715
addChildValues_ = false ;
716
- indented_ = false ;
716
+ indented_ = true ;
717
717
indentString_ = " " ;
718
718
writeCommentBeforeValue (root);
719
+ if (!indented_) writeIndent ();
720
+ indented_ = true ;
719
721
writeValue (root);
720
722
writeCommentAfterValueOnSameLine (root);
721
723
sout_ << " \n " ;
@@ -878,20 +880,17 @@ void BuiltStyledStreamWriter::writeCommentBeforeValue(Value const& root) {
878
880
if (!root.hasComment (commentBefore))
879
881
return ;
880
882
881
- sout_ << " \n " ;
882
- writeIndent ();
883
+ if (!indented_) writeIndent ();
883
884
const std::string& comment = root.getComment (commentBefore);
884
885
std::string::const_iterator iter = comment.begin ();
885
886
while (iter != comment.end ()) {
886
887
sout_ << *iter;
887
888
if (*iter == ' \n ' &&
888
889
(iter != comment.end () && *(iter + 1 ) == ' /' ))
889
- writeIndent ();
890
+ // writeIndent(); // would write extra newline
891
+ sout_ << indentString_;
890
892
++iter;
891
893
}
892
-
893
- // Comments are stripped of trailing newlines, so add one here
894
- sout_ << " \n " ;
895
894
indented_ = false ;
896
895
}
897
896
@@ -900,9 +899,8 @@ void BuiltStyledStreamWriter::writeCommentAfterValueOnSameLine(Value const& root
900
899
sout_ << " " + root.getComment (commentAfterOnSameLine);
901
900
902
901
if (root.hasComment (commentAfter)) {
903
- sout_ << " \n " ;
902
+ writeIndent () ;
904
903
sout_ << root.getComment (commentAfter);
905
- sout_ << " \n " ;
906
904
}
907
905
}
908
906
You can’t perform that action at this time.
0 commit comments