add patch_inplace function (#3581)

* add patch_inplace function to json class

* add documentation

* fix up docs
This commit is contained in:
Wolf Vollprecht
2022-07-21 16:27:59 +02:00
committed by GitHub
parent 4b6d3638ca
commit 09fb4819ff
6 changed files with 131 additions and 12 deletions

View File

@@ -4620,13 +4620,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @name JSON Patch functions
/// @{
/// @brief applies a JSON patch
/// @brief applies a JSON patch in-place without copying the object
/// @sa https://json.nlohmann.me/api/basic_json/patch/
basic_json patch(const basic_json& json_patch) const
void patch_inplace(const basic_json& json_patch)
{
// make a working copy to apply the patch to
basic_json result = *this;
basic_json& result = *this;
// the valid JSON Patch operations
enum class patch_operations {add, remove, replace, move, copy, test, invalid};
@@ -4890,7 +4888,14 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
}
}
}
}
/// @brief applies a JSON patch to a copy of the current object
/// @sa https://json.nlohmann.me/api/basic_json/patch/
basic_json patch(const basic_json& json_patch) const
{
basic_json result = *this;
result.patch_inplace(json_patch);
return result;
}
@@ -5028,7 +5033,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return result;
}
/// @}
////////////////////////////////