mirror of
https://github.com/nlohmann/json.git
synced 2026-03-13 04:31:24 +00:00
add patch_inplace function (#3581)
* add patch_inplace function to json class * add documentation * fix up docs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user