Merge pull request #124 from cdunn2001/assign-with-comments

1.2.0

 `operator=()` (which already performed a deep-copy) now includes comments. This change is probably harmless in all practical cases. But just in case, we bump the minor version.

Address #47.
This commit is contained in:
Christopher Dunn 2015-01-20 12:49:51 -06:00
commit 4ce4bb8404
9 changed files with 57 additions and 24 deletions

View File

@ -235,23 +235,26 @@ Json::Value obj_value(Json::objectValue); // {}
Value(const CppTL::ConstString& value);
#endif
Value(bool value);
/// Deep copy.
Value(const Value& other);
~Value();
// Deep copy, then swap(other).
Value& operator=(Value other);
/// Swap values.
/// Swap everything.
void swap(Value& other);
/// Swap values but leave comments and source offsets in place.
void swapPayload(Value& other);
ValueType type() const;
/// Compare payload only, not comments etc.
bool operator<(const Value& other) const;
bool operator<=(const Value& other) const;
bool operator>=(const Value& other) const;
bool operator>(const Value& other) const;
bool operator==(const Value& other) const;
bool operator!=(const Value& other) const;
int compare(const Value& other) const;
const char* asCString() const;
@ -442,9 +445,6 @@ private:
Value& resolveReference(const char* key, bool isStatic);
/// Swap values but leave comments and source offsets in place.
void swapPayload(Value& other);
#ifdef JSON_VALUE_USE_INTERNAL_MAP
inline bool isItemAvailable() const { return itemIsUsed_ == 0; }

View File

@ -4,10 +4,10 @@
#ifndef JSON_VERSION_H_INCLUDED
# define JSON_VERSION_H_INCLUDED
# define JSONCPP_VERSION_STRING "1.1.1"
# define JSONCPP_VERSION_STRING "1.2.0"
# define JSONCPP_VERSION_MAJOR 1
# define JSONCPP_VERSION_MINOR 1
# define JSONCPP_VERSION_PATCH 1
# define JSONCPP_VERSION_MINOR 2
# define JSONCPP_VERSION_PATCH 0
# define JSONCPP_VERSION_QUALIFIER
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))

View File

@ -163,26 +163,36 @@ bool Reader::readValue() {
successful = decodeString(token);
break;
case tokenTrue:
currentValue() = true;
{
Value v(true);
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
}
break;
case tokenFalse:
currentValue() = false;
{
Value v(false);
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
}
break;
case tokenNull:
currentValue() = Value();
{
Value v;
currentValue().swapPayload(v);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
}
break;
case tokenArraySeparator:
if (features_.allowDroppedNullPlaceholders_) {
// "Un-read" the current token and mark the current value as a null
// token.
current_--;
currentValue() = Value();
Value v;
currentValue().swapPayload(v);
currentValue().setOffsetStart(current_ - begin_ - 1);
currentValue().setOffsetLimit(current_ - begin_);
break;
@ -393,7 +403,8 @@ bool Reader::readString() {
bool Reader::readObject(Token& tokenStart) {
Token tokenName;
std::string name;
currentValue() = Value(objectValue);
Value init(objectValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(tokenStart.start_ - begin_);
while (readToken(tokenName)) {
bool initialTokenOk = true;
@ -446,7 +457,8 @@ bool Reader::readObject(Token& tokenStart) {
}
bool Reader::readArray(Token& tokenStart) {
currentValue() = Value(arrayValue);
Value init(arrayValue);
currentValue().swapPayload(init);
currentValue().setOffsetStart(tokenStart.start_ - begin_);
skipSpaces();
if (*current_ == ']') // empty array
@ -486,7 +498,7 @@ bool Reader::decodeNumber(Token& token) {
Value decoded;
if (!decodeNumber(token, decoded))
return false;
currentValue() = decoded;
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
@ -536,7 +548,7 @@ bool Reader::decodeDouble(Token& token) {
Value decoded;
if (!decodeDouble(token, decoded))
return false;
currentValue() = decoded;
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;
@ -579,10 +591,11 @@ bool Reader::decodeDouble(Token& token, Value& decoded) {
}
bool Reader::decodeString(Token& token) {
std::string decoded;
if (!decodeString(token, decoded))
std::string decoded_string;
if (!decodeString(token, decoded_string))
return false;
currentValue() = decoded;
Value decoded(decoded_string);
currentValue().swapPayload(decoded);
currentValue().setOffsetStart(token.start_ - begin_);
currentValue().setOffsetLimit(token.end_ - begin_);
return true;

View File

@ -406,7 +406,7 @@ Value::~Value() {
}
Value& Value::operator=(Value other) {
swapPayload(other);
swap(other);
return *this;
}

View File

@ -1,4 +1,5 @@
.={}
// Comment for array
.test=[]
.test[0]={}
.test[0].a="aaa"

View File

@ -1,5 +1,6 @@
{
"test":
// Comment for array
[
{ "a" : "aaa" }, // Comment for a
{ "b" : "bbb" }, // Comment for b

View File

@ -11,4 +11,13 @@
// Multiline comment cpp-style
// Second line
.cpp-test.c=3
.cpp-test.d=4
// Comment before double
.cpp-test.d=4.1
// Comment before string
.cpp-test.e="e-string"
// Comment before true
.cpp-test.f=true
// Comment before false
.cpp-test.g=false
// Comment before null
.cpp-test.h=null

View File

@ -12,6 +12,15 @@
// Multiline comment cpp-style
// Second line
"c" : 3,
"d" : 4
// Comment before double
"d" : 4.1,
// Comment before string
"e" : "e-string",
// Comment before true
"f" : true,
// Comment before false
"g" : false,
// Comment before null
"h" : null
}
}

View File

@ -1 +1 @@
1.1.1
1.2.0