File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -466,8 +466,10 @@ void StyledStreamWriter::write(std::ostream& out, const Value& root) {
466
466
document_ = &out;
467
467
addChildValues_ = false ;
468
468
indentString_ = " " ;
469
- indented_ = false ;
469
+ indented_ = true ;
470
470
writeCommentBeforeValue (root);
471
+ if (!indented_) writeIndent ();
472
+ indented_ = true ;
471
473
writeValue (root);
472
474
writeCommentAfterValueOnSameLine (root);
473
475
*document_ << " \n " ;
@@ -631,32 +633,29 @@ void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
631
633
if (!root.hasComment (commentBefore))
632
634
return ;
633
635
634
- *document_ << " \n " ;
635
- writeIndent ();
636
+ if (!indented_) writeIndent ();
636
637
const std::string& comment = root.getComment (commentBefore);
637
638
std::string::const_iterator iter = comment.begin ();
638
639
while (iter != comment.end ()) {
639
640
*document_ << *iter;
640
641
if (*iter == ' \n ' &&
641
642
(iter != comment.end () && *(iter + 1 ) == ' /' ))
642
- writeIndent ();
643
+ // writeIndent(); // would include newline
644
+ *document_ << indentString_;
643
645
++iter;
644
646
}
645
-
646
- // Comments are stripped of trailing newlines, so add one here
647
- *document_ << " \n " ;
648
647
indented_ = false ;
649
648
}
650
649
651
650
void StyledStreamWriter::writeCommentAfterValueOnSameLine (const Value& root) {
652
651
if (root.hasComment (commentAfterOnSameLine))
653
- *document_ << " " + root.getComment (commentAfterOnSameLine);
652
+ *document_ << root.getComment (commentAfterOnSameLine);
654
653
655
654
if (root.hasComment (commentAfter)) {
656
- *document_ << " \n " ;
655
+ writeIndent () ;
657
656
*document_ << root.getComment (commentAfter);
658
- *document_ << " \n " ;
659
657
}
658
+ indented_ = false ;
660
659
}
661
660
662
661
bool StyledStreamWriter::hasCommentForValue (const Value& value) {
You can’t perform that action at this time.
0 commit comments