Comment reading/write improvements

This patch fixes some aspects of reading and writing comments:
- Multiple C++-style comments before a Json value had extra newlines appended to them. This patch removes the addition of those newlines.
- Comments written before Json values in the StyledWriter were not indented to match the indentation level of the value. This patch adds indentation to comments.
- Fixed inconsistency in newlines following C- and C++-style comments being saved as part of the comment. All newlines at the end of a comment are now removed.
- Added an additional test of comments.

https://sourceforge.net/p/jsoncpp/patches/25/
This commit is contained in:
Christopher Dunn
2014-04-19 21:19:24 +00:00
parent ea0797351f
commit 09439b7bc7
4 changed files with 48 additions and 1 deletions

View File

@@ -483,7 +483,20 @@ StyledWriter::writeCommentBeforeValue( const Value &root )
{
if ( !root.hasComment( commentBefore ) )
return;
document_ += normalizeEOL( root.getComment( commentBefore ) );
document_ += "\n";
writeIndent();
std::string normalizedComment = normalizeEOL( root.getComment( commentBefore ) );
std::string::const_iterator iter = normalizedComment.begin();
while ( iter != normalizedComment.end() )
{
document_ += *iter;
if ( *iter == '\n' && *(iter+1) == '/' )
writeIndent();
++iter;
}
// Comments are stripped of newlines, so add one here
document_ += "\n";
}