MCPcopy Create free account
hub / github.com/cinder/Cinder / patch

Function patch

include/nlohmann/json.hpp:4226–4493  ·  view source on GitHub ↗

@brief applies a JSON patch @sa https://json.nlohmann.me/api/basic_json/patch/

Source from the content-addressed store, hash-verified

4224 /// @brief applies a JSON patch
4225 /// @sa https://json.nlohmann.me/api/basic_json/patch/
4226 basic_json patch(const basic_json& json_patch) const
4227 {
4228 // make a working copy to apply the patch to
4229 basic_json result = *this;
4230
4231 // the valid JSON Patch operations
4232 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
4233
4234 const auto get_op = [](const std::string & op)
4235 {
4236 if (op == "add")
4237 {
4238 return patch_operations::add;
4239 }
4240 if (op == "remove")
4241 {
4242 return patch_operations::remove;
4243 }
4244 if (op == "replace")
4245 {
4246 return patch_operations::replace;
4247 }
4248 if (op == "move")
4249 {
4250 return patch_operations::move;
4251 }
4252 if (op == "copy")
4253 {
4254 return patch_operations::copy;
4255 }
4256 if (op == "test")
4257 {
4258 return patch_operations::test;
4259 }
4260
4261 return patch_operations::invalid;
4262 };
4263
4264 // wrapper for "add" operation; add value at ptr
4265 const auto operation_add = [&result](json_pointer & ptr, basic_json val)
4266 {
4267 // adding to the root of the target document means replacing it
4268 if (ptr.empty())
4269 {
4270 result = val;
4271 return;
4272 }
4273
4274 // make sure the top element of the pointer exists
4275 json_pointer top_pointer = ptr.top();
4276 if (top_pointer != ptr)
4277 {
4278 result.at(top_pointer);
4279 }
4280
4281 // get reference to parent of JSON pointer ptr
4282 const auto last_path = ptr.back();
4283 ptr.pop_back();

Callers

nothing calls this directly

Calls 15

atMethod · 0.80
backMethod · 0.80
pop_backMethod · 0.80
createFunction · 0.70
to_stringFunction · 0.50
emptyMethod · 0.45
topMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected