1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

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

@ -23445,13 +23445,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};
@ -23715,7 +23713,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;
}
@ -23853,7 +23858,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
return result;
}
/// @}
////////////////////////////////