mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-07 17:14:56 +02:00
rm trailing newlines for *all* comments
This will make it easier to fix newlines consistently.
This commit is contained in:
parent
7312b1022d
commit
1e3149ab75
@ -432,9 +432,11 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
// EnumValues enumValues() const;
|
// EnumValues enumValues() const;
|
||||||
//# endif
|
//# endif
|
||||||
|
|
||||||
/// Comments must be //... or /* ... */
|
/// \deprecated Always pass len.
|
||||||
void setComment(const char* comment, CommentPlacement placement);
|
void setComment(const char* comment, CommentPlacement placement);
|
||||||
/// Comments must be //... or /* ... */
|
/// Comments must be //... or /* ... */
|
||||||
|
void setComment(const char* comment, size_t len, CommentPlacement placement);
|
||||||
|
/// Comments must be //... or /* ... */
|
||||||
void setComment(const std::string& comment, CommentPlacement placement);
|
void setComment(const std::string& comment, CommentPlacement placement);
|
||||||
bool hasComment(CommentPlacement placement) const;
|
bool hasComment(CommentPlacement placement) const;
|
||||||
/// Include delimiters and embedded newlines.
|
/// Include delimiters and embedded newlines.
|
||||||
@ -477,7 +479,7 @@ private:
|
|||||||
CommentInfo();
|
CommentInfo();
|
||||||
~CommentInfo();
|
~CommentInfo();
|
||||||
|
|
||||||
void setComment(const char* text);
|
void setComment(const char* text, size_t len);
|
||||||
|
|
||||||
char* comment_;
|
char* comment_;
|
||||||
};
|
};
|
||||||
|
@ -135,9 +135,6 @@ bool Reader::readValue() {
|
|||||||
bool successful = true;
|
bool successful = true;
|
||||||
|
|
||||||
if (collectComments_ && !commentsBefore_.empty()) {
|
if (collectComments_ && !commentsBefore_.empty()) {
|
||||||
// Remove newline at the end of the comment
|
|
||||||
if (commentsBefore_[commentsBefore_.size() - 1] == '\n')
|
|
||||||
commentsBefore_.resize(commentsBefore_.size() - 1);
|
|
||||||
currentValue().setComment(commentsBefore_, commentBefore);
|
currentValue().setComment(commentsBefore_, commentBefore);
|
||||||
commentsBefore_ = "";
|
commentsBefore_ = "";
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ Value::CommentInfo::~CommentInfo() {
|
|||||||
releaseStringValue(comment_);
|
releaseStringValue(comment_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::CommentInfo::setComment(const char* text) {
|
void Value::CommentInfo::setComment(const char* text, size_t len) {
|
||||||
if (comment_) {
|
if (comment_) {
|
||||||
releaseStringValue(comment_);
|
releaseStringValue(comment_);
|
||||||
comment_ = 0;
|
comment_ = 0;
|
||||||
@ -151,7 +151,7 @@ void Value::CommentInfo::setComment(const char* text) {
|
|||||||
text[0] == '\0' || text[0] == '/',
|
text[0] == '\0' || text[0] == '/',
|
||||||
"in Json::Value::setComment(): Comments must start with /");
|
"in Json::Value::setComment(): Comments must start with /");
|
||||||
// It seems that /**/ style comments are acceptable as well.
|
// It seems that /**/ style comments are acceptable as well.
|
||||||
comment_ = duplicateStringValue(text);
|
comment_ = duplicateStringValue(text, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
// //////////////////////////////////////////////////////////////////
|
// //////////////////////////////////////////////////////////////////
|
||||||
@ -369,7 +369,8 @@ Value::Value(const Value& other)
|
|||||||
for (int comment = 0; comment < numberOfCommentPlacement; ++comment) {
|
for (int comment = 0; comment < numberOfCommentPlacement; ++comment) {
|
||||||
const CommentInfo& otherComment = other.comments_[comment];
|
const CommentInfo& otherComment = other.comments_[comment];
|
||||||
if (otherComment.comment_)
|
if (otherComment.comment_)
|
||||||
comments_[comment].setComment(otherComment.comment_);
|
comments_[comment].setComment(
|
||||||
|
otherComment.comment_, strlen(otherComment.comment_));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1227,14 +1228,22 @@ bool Value::isArray() const { return type_ == arrayValue; }
|
|||||||
|
|
||||||
bool Value::isObject() const { return type_ == objectValue; }
|
bool Value::isObject() const { return type_ == objectValue; }
|
||||||
|
|
||||||
void Value::setComment(const char* comment, CommentPlacement placement) {
|
void Value::setComment(const char* comment, size_t len, CommentPlacement placement) {
|
||||||
if (!comments_)
|
if (!comments_)
|
||||||
comments_ = new CommentInfo[numberOfCommentPlacement];
|
comments_ = new CommentInfo[numberOfCommentPlacement];
|
||||||
comments_[placement].setComment(comment);
|
if ((len > 0) && (comment[len-1] == '\n')) {
|
||||||
|
// Always discard trailing newline, to aid indentation.
|
||||||
|
len -= 1;
|
||||||
|
}
|
||||||
|
comments_[placement].setComment(comment, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Value::setComment(const char* comment, CommentPlacement placement) {
|
||||||
|
setComment(comment, strlen(comment), placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::setComment(const std::string& comment, CommentPlacement placement) {
|
void Value::setComment(const std::string& comment, CommentPlacement placement) {
|
||||||
setComment(comment.c_str(), placement);
|
setComment(comment.c_str(), comment.length(), placement);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::hasComment(CommentPlacement placement) const {
|
bool Value::hasComment(CommentPlacement placement) const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user