From 39bb759b0e59f880bdaa51ab7f28927afa75989c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfram=20R=C3=B6sler?= Date: Mon, 16 Oct 2017 13:09:19 +0200 Subject: [PATCH 1/2] Un-deprecate removeMember overloads, return void Sometimes we just want to remove something we don't need anymore. Having to supply a return buffer for the removeMember function to return something we don't care about is a nuisance. There are removeMember overloads that don't need a return buffer but they are deprecated. This commit un-deprecates these overloads and modifies them to return nothing (void) instead of the object that was removed. Further discussion: https://github.com/open-source-parsers/jsoncpp/pull/689 WARNING: Changes the return type of the formerly deprecated removeMember overloads from Value to void. May break existing client code. --- include/json/value.h | 6 ++---- src/lib_json/json_value.cpp | 11 +++++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/json/value.h b/include/json/value.h index ebca175db..d1c18f11a 100644 --- a/include/json/value.h +++ b/include/json/value.h @@ -518,13 +518,11 @@ Json::Value obj_value(Json::objectValue); // {} /// \pre type() is objectValue or nullValue /// \post type() is unchanged /// \deprecated - JSONCPP_DEPRECATED("") - Value removeMember(const char* key); + void removeMember(const char* key); /// Same as removeMember(const char*) /// \param key may contain embedded nulls. /// \deprecated - JSONCPP_DEPRECATED("") - Value removeMember(const JSONCPP_STRING& key); + void removeMember(const JSONCPP_STRING& key); /// Same as removeMember(const char* begin, const char* end, Value* removed), /// but 'key' is null-terminated. bool removeMember(const char* key, Value* removed); diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 2a53138bc..e7f0a828a 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1187,18 +1187,17 @@ bool Value::removeMember(JSONCPP_STRING const& key, Value* removed) { return removeMember(key.data(), key.data() + key.length(), removed); } -Value Value::removeMember(const char* key) +void Value::removeMember(const char* key) { JSON_ASSERT_MESSAGE(type_ == nullValue || type_ == objectValue, "in Json::Value::removeMember(): requires objectValue"); if (type_ == nullValue) - return nullSingleton(); + return; - Value removed; // null - removeMember(key, key + strlen(key), &removed); - return removed; // still null if removeMember() did nothing + CZString actualKey(key, strlen(key), CZString::noDuplication); + value_.map_->erase(actualKey); } -Value Value::removeMember(const JSONCPP_STRING& key) +void Value::removeMember(const JSONCPP_STRING& key) { return removeMember(key.c_str()); } From f6f8f7b696223cace4de681e6d372d59b30c9bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wolfram=20R=C3=B6sler?= Date: Tue, 17 Oct 2017 11:37:09 +0200 Subject: [PATCH 2/2] Minor stylistic fixes Don't explicitly return a void value from a void function. Also, convert size_t to unsigned in the CZString ctor to avoid a compiler warning. --- src/lib_json/json_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index e7f0a828a..23a8f97d8 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1194,12 +1194,12 @@ void Value::removeMember(const char* key) if (type_ == nullValue) return; - CZString actualKey(key, strlen(key), CZString::noDuplication); + CZString actualKey(key, unsigned(strlen(key)), CZString::noDuplication); value_.map_->erase(actualKey); } void Value::removeMember(const JSONCPP_STRING& key) { - return removeMember(key.c_str()); + removeMember(key.c_str()); } bool Value::removeIndex(ArrayIndex index, Value* removed) {