MCPcopy Create free account
hub / github.com/CalcProgrammer1/OpenRGB / patch

Function patch

dependencies/json/json.hpp:24745–25002  ·  view source on GitHub ↗

! @brief applies a JSON patch [JSON Patch](http://jsonpatch.com) defines a JSON document structure for expressing a sequence of operations to apply to a JSON) document. With this function, a JSON Patch is applied to the current JSON value by executing all operations from the patch. @param[in] json_patch JSON patch document @return patched document @note The appl

Source from the content-addressed store, hash-verified

24743 @since version 2.0.0
24744 */
24745 basic_json patch(const basic_json& json_patch) const
24746 {
24747 // make a working copy to apply the patch to
24748 basic_json result = *this;
24749
24750 // the valid JSON Patch operations
24751 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
24752
24753 const auto get_op = [](const std::string & op)
24754 {
24755 if (op == "add")
24756 {
24757 return patch_operations::add;
24758 }
24759 if (op == "remove")
24760 {
24761 return patch_operations::remove;
24762 }
24763 if (op == "replace")
24764 {
24765 return patch_operations::replace;
24766 }
24767 if (op == "move")
24768 {
24769 return patch_operations::move;
24770 }
24771 if (op == "copy")
24772 {
24773 return patch_operations::copy;
24774 }
24775 if (op == "test")
24776 {
24777 return patch_operations::test;
24778 }
24779
24780 return patch_operations::invalid;
24781 };
24782
24783 // wrapper for "add" operation; add value at ptr
24784 const auto operation_add = [&result](json_pointer & ptr, basic_json val)
24785 {
24786 // adding to the root of the target document means replacing it
24787 if (ptr.empty())
24788 {
24789 result = val;
24790 return;
24791 }
24792
24793 // make sure the top element of the pointer exists
24794 json_pointer top_pointer = ptr.top();
24795 if (top_pointer != ptr)
24796 {
24797 result.at(top_pointer);
24798 }
24799
24800 // get reference to parent of JSON pointer ptr
24801 const auto last_path = ptr.back();
24802 ptr.pop_back();

Callers

nothing calls this directly

Calls 12

to_stringFunction · 0.85
createFunction · 0.70
emptyMethod · 0.45
pop_backMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
findMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected