mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-04-27 18:30:50 +02:00
Merge pull request #144 from cdunn2001/proper-comment-lfs
proper newlines for comments This alters `StyledStreamWriter`, but not `StyledWriter`.
This commit is contained in:
commit
c038e08efc
@ -466,8 +466,10 @@ void StyledStreamWriter::write(std::ostream& out, const Value& root) {
|
|||||||
document_ = &out;
|
document_ = &out;
|
||||||
addChildValues_ = false;
|
addChildValues_ = false;
|
||||||
indentString_ = "";
|
indentString_ = "";
|
||||||
indented_ = false;
|
indented_ = true;
|
||||||
writeCommentBeforeValue(root);
|
writeCommentBeforeValue(root);
|
||||||
|
if (!indented_) writeIndent();
|
||||||
|
indented_ = true;
|
||||||
writeValue(root);
|
writeValue(root);
|
||||||
writeCommentAfterValueOnSameLine(root);
|
writeCommentAfterValueOnSameLine(root);
|
||||||
*document_ << "\n";
|
*document_ << "\n";
|
||||||
@ -631,32 +633,29 @@ void StyledStreamWriter::writeCommentBeforeValue(const Value& root) {
|
|||||||
if (!root.hasComment(commentBefore))
|
if (!root.hasComment(commentBefore))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
*document_ << "\n";
|
if (!indented_) writeIndent();
|
||||||
writeIndent();
|
|
||||||
const std::string& comment = root.getComment(commentBefore);
|
const std::string& comment = root.getComment(commentBefore);
|
||||||
std::string::const_iterator iter = comment.begin();
|
std::string::const_iterator iter = comment.begin();
|
||||||
while (iter != comment.end()) {
|
while (iter != comment.end()) {
|
||||||
*document_ << *iter;
|
*document_ << *iter;
|
||||||
if (*iter == '\n' &&
|
if (*iter == '\n' &&
|
||||||
(iter != comment.end() && *(iter + 1) == '/'))
|
(iter != comment.end() && *(iter + 1) == '/'))
|
||||||
writeIndent();
|
// writeIndent(); // would include newline
|
||||||
|
*document_ << indentString_;
|
||||||
++iter;
|
++iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments are stripped of trailing newlines, so add one here
|
|
||||||
*document_ << "\n";
|
|
||||||
indented_ = false;
|
indented_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) {
|
void StyledStreamWriter::writeCommentAfterValueOnSameLine(const Value& root) {
|
||||||
if (root.hasComment(commentAfterOnSameLine))
|
if (root.hasComment(commentAfterOnSameLine))
|
||||||
*document_ << " " + root.getComment(commentAfterOnSameLine);
|
*document_ << root.getComment(commentAfterOnSameLine);
|
||||||
|
|
||||||
if (root.hasComment(commentAfter)) {
|
if (root.hasComment(commentAfter)) {
|
||||||
*document_ << "\n";
|
writeIndent();
|
||||||
*document_ << root.getComment(commentAfter);
|
*document_ << root.getComment(commentAfter);
|
||||||
*document_ << "\n";
|
|
||||||
}
|
}
|
||||||
|
indented_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StyledStreamWriter::hasCommentForValue(const Value& value) {
|
bool StyledStreamWriter::hasCommentForValue(const Value& value) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user