diff --git a/include/json/value.h b/include/json/value.h index 3473c7e..93112d1 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -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; } diff --git a/include/json/version.h b/include/json/version.h index baf5daa..4565dc1 100644 --- a/include/json/version.h +++ b/include/json/version.h @@ -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)) diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 2e587ab..b61f1b1 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -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; diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 85b26ce..0a7fb85 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -406,7 +406,7 @@ Value::~Value() { } Value& Value::operator=(Value other) { - swapPayload(other); + swap(other); return *this; } diff --git a/test/data/test_comment_01.expected b/test/data/test_comment_01.expected index 2a7f00c..d8548d1 100644 --- a/test/data/test_comment_01.expected +++ b/test/data/test_comment_01.expected @@ -1,4 +1,5 @@ .={} +// Comment for array .test=[] .test[0]={} .test[0].a="aaa" diff --git a/test/data/test_comment_01.json b/test/data/test_comment_01.json index 7363490..db7c6a4 100644 --- a/test/data/test_comment_01.json +++ b/test/data/test_comment_01.json @@ -1,5 +1,6 @@ { "test": + // Comment for array [ { "a" : "aaa" }, // Comment for a { "b" : "bbb" }, // Comment for b diff --git a/test/data/test_comment_02.expected b/test/data/test_comment_02.expected index 88d2bd0..8986dba 100644 --- a/test/data/test_comment_02.expected +++ b/test/data/test_comment_02.expected @@ -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 diff --git a/test/data/test_comment_02.json b/test/data/test_comment_02.json index 297d889..f5042e0 100644 --- a/test/data/test_comment_02.json +++ b/test/data/test_comment_02.json @@ -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 } } diff --git a/version b/version index cd075f2..de23bf3 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.1.1 \ No newline at end of file +1.2.0 \ No newline at end of file