diff --git a/CMakeLists.txt b/CMakeLists.txt index 2de4024..a992437 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,12 +63,12 @@ if(NOT DEFINED CMAKE_BUILD_TYPE) endif() project(JSONCPP - VERSION 1.8.4 # [.[.[.]]] + VERSION 1.9.0 # [.[.[.]]] LANGUAGES CXX) set( JSONCPP_VERSION ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH} ) message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}") -set( JSONCPP_SOVERSION 19 ) +set( JSONCPP_SOVERSION 21 ) option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON) option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON) diff --git a/include/json/value.h b/include/json/value.h index 2e94b37..5f8d214 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -524,7 +524,7 @@ Json::Value obj_value(Json::objectValue); // {} /// Most general and efficient version of object-mutators. /// \note As stated elsewhere, behavior is undefined if (end-begin) >= 2^30 /// \return non-zero, but JSON_ASSERT if this is neither object nor nullValue. - Value const* demand(char const* begin, char const* end); + Value* demand(char const* begin, char const* end); /// \brief Remove and return the named member. /// /// Do nothing if it did not exist. diff --git a/meson.build b/meson.build index a338cc0..106e17f 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project( 'jsoncpp', 'cpp', - version : '1.8.4', + version : '1.9.0', default_options : [ 'buildtype=release', 'cpp_std=c++11', @@ -62,7 +62,7 @@ jsoncpp_lib = library( 'src/lib_json/json_reader.cpp', 'src/lib_json/json_value.cpp', 'src/lib_json/json_writer.cpp'], - soversion : 20, + soversion : 21, install : true, include_directories : jsoncpp_include_directories, cpp_args: dll_export_flag) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index fe5d8b3..b046c19 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1115,7 +1115,7 @@ bool Value::isValidIndex(ArrayIndex index) const { return index < size(); } Value const* Value::find(char const* begin, char const* end) const { JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue, - "in Json::Value::find(key, end, found): requires " + "in Json::Value::find(begin, end): requires " "objectValue or nullValue"); if (type() == nullValue) return nullptr; @@ -1126,6 +1126,12 @@ Value const* Value::find(char const* begin, char const* end) const { return nullptr; return &(*it).second; } +Value* Value::demand(char const* begin, char const* end) { + JSON_ASSERT_MESSAGE(type() == nullValue || type() == objectValue, + "in Json::Value::demand(begin, end): requires " + "objectValue or nullValue"); + return &resolveReference(begin, end); +} const Value& Value::operator[](const char* key) const { Value const* found = find(key, key + strlen(key)); if (!found) diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 2df51b5..280f7ea 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -204,6 +204,26 @@ JSONTEST_FIXTURE(ValueTest, objects) { JSONTEST_ASSERT_EQUAL(Json::Value(1234), constObject["id"]); JSONTEST_ASSERT_EQUAL(Json::Value(), constObject["unknown id"]); + // Access through find() + const char idKey[] = "id"; + const Json::Value* foundId = object1_.find(idKey, idKey + strlen(idKey)); + JSONTEST_ASSERT(foundId != nullptr); + JSONTEST_ASSERT_EQUAL(Json::Value(1234), *foundId); + + const char unknownIdKey[] = "unknown id"; + const Json::Value* foundUnknownId = object1_.find(unknownIdKey, unknownIdKey + strlen(unknownIdKey)); + JSONTEST_ASSERT_EQUAL(nullptr, foundUnknownId); + + // Access through demand() + const char yetAnotherIdKey[] = "yet another id"; + const Json::Value* foundYetAnotherId = object1_.find(yetAnotherIdKey, yetAnotherIdKey + strlen(yetAnotherIdKey)); + JSONTEST_ASSERT_EQUAL(nullptr, foundYetAnotherId); + Json::Value* demandedYetAnotherId = object1_.demand(yetAnotherIdKey, yetAnotherIdKey + strlen(yetAnotherIdKey)); + JSONTEST_ASSERT(demandedYetAnotherId != nullptr); + *demandedYetAnotherId = "baz"; + + JSONTEST_ASSERT_EQUAL(Json::Value("baz"), object1_["yet another id"]); + // Access through non-const reference JSONTEST_ASSERT_EQUAL(Json::Value(1234), object1_["id"]); JSONTEST_ASSERT_EQUAL(Json::Value(), object1_["unknown id"]);