mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-06-09 17:57:34 +02:00
Allow Json::Value to be used in a boolean context (#695)
Must bump soversion too.
This commit is contained in:
parent
c39aa295e4
commit
9079422ac1
@ -400,8 +400,8 @@ Json::Value obj_value(Json::objectValue); // {}
|
|||||||
/// otherwise, false.
|
/// otherwise, false.
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
||||||
/// Return isNull()
|
/// Return !isNull()
|
||||||
bool operator!() const;
|
explicit operator bool() const;
|
||||||
|
|
||||||
/// Remove all object members and array elements.
|
/// Remove all object members and array elements.
|
||||||
/// \pre type() is arrayValue, objectValue, or nullValue
|
/// \pre type() is arrayValue, objectValue, or nullValue
|
||||||
|
@ -962,7 +962,7 @@ bool Value::empty() const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::operator!() const { return isNull(); }
|
Value::operator bool() const { return ! isNull(); }
|
||||||
|
|
||||||
void Value::clear() {
|
void Value::clear() {
|
||||||
JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue ||
|
JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == arrayValue ||
|
||||||
|
@ -308,6 +308,12 @@ JSONTEST_FIXTURE(ValueTest, null) {
|
|||||||
JSONTEST_ASSERT_STRING_EQUAL("", null_.asString());
|
JSONTEST_ASSERT_STRING_EQUAL("", null_.asString());
|
||||||
|
|
||||||
JSONTEST_ASSERT_EQUAL(Json::Value::null, null_);
|
JSONTEST_ASSERT_EQUAL(Json::Value::null, null_);
|
||||||
|
|
||||||
|
// Test using a Value in a boolean context (false iff null)
|
||||||
|
JSONTEST_ASSERT_EQUAL(null_,false);
|
||||||
|
JSONTEST_ASSERT_EQUAL(object1_,true);
|
||||||
|
JSONTEST_ASSERT_EQUAL(!null_,true);
|
||||||
|
JSONTEST_ASSERT_EQUAL(!object1_,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONTEST_FIXTURE(ValueTest, strings) {
|
JSONTEST_FIXTURE(ValueTest, strings) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user