From 3efc587fbabd4a4e6114a82a0acd80b844e64a0e Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Fri, 23 Jan 2015 09:03:00 -0600 Subject: [PATCH] make StyledStreamWriter work more like StyledWriter tests pass --- src/lib_json/json_writer.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 778661c..099cc29 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -628,7 +628,20 @@ void StyledStreamWriter::unindent() { void StyledStreamWriter::writeCommentBeforeValue(const Value& root) { if (!root.hasComment(commentBefore)) return; - *document_ << root.getComment(commentBefore); + + *document_ << "\n"; + writeIndent(); + const std::string& comment = root.getComment(commentBefore); + std::string::const_iterator iter = comment.begin(); + while (iter != comment.end()) { + *document_ << *iter; + if (*iter == '\n' && + (iter != comment.end() && *(iter + 1) == '/')) + writeIndent(); + ++iter; + } + + // Comments are stripped of trailing newlines, so add one here *document_ << "\n"; }