Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/json/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -442,9 +445,6 @@ Json::Value obj_value(Json::objectValue); // {}

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; }

Expand Down
6 changes: 3 additions & 3 deletions include/json/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
35 changes: 24 additions & 11 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Value::~Value() {
}

Value& Value::operator=(Value other) {
swapPayload(other);
swap(other);
return *this;
}

Expand Down
1 change: 1 addition & 0 deletions test/data/test_comment_01.expected
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.={}
// Comment for array
.test=[]
.test[0]={}
.test[0].a="aaa"
Expand Down
1 change: 1 addition & 0 deletions test/data/test_comment_01.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"test":
// Comment for array
[
{ "a" : "aaa" }, // Comment for a
{ "b" : "bbb" }, // Comment for b
Expand Down
11 changes: 10 additions & 1 deletion test/data/test_comment_02.expected
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion test/data/test_comment_02.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.2.0