| 86 | |
| 87 | template <typename Json> |
| 88 | jsonpointer::basic_json_pointer<typename Json::char_type> definite_path(const Json& root, jsonpointer::basic_json_pointer<typename Json::char_type>& location) |
| 89 | { |
| 90 | using char_type = typename Json::char_type; |
| 91 | using string_type = std::basic_string<char_type>; |
| 92 | |
| 93 | auto rit = location.rbegin(); |
| 94 | if (rit == location.rend()) |
| 95 | { |
| 96 | return location; |
| 97 | } |
| 98 | |
| 99 | if (*rit != jsonpatch_names<char_type>::dash_name()) |
| 100 | { |
| 101 | return location; |
| 102 | } |
| 103 | |
| 104 | std::vector<string_type> tokens; |
| 105 | for (auto it = location.begin(); it != location.rbegin().base()-1; ++it) |
| 106 | { |
| 107 | tokens.push_back(*it); |
| 108 | } |
| 109 | jsonpointer::basic_json_pointer<char_type> pointer(tokens); |
| 110 | |
| 111 | std::error_code ec; |
| 112 | |
| 113 | Json val = jsonpointer::get(root, pointer, ec); |
| 114 | if (ec || !val.is_array()) |
| 115 | { |
| 116 | return location; |
| 117 | } |
| 118 | string_type last_token; |
| 119 | jsoncons::from_integer(val.size(), last_token); |
| 120 | tokens.emplace_back(std::move(last_token)); |
| 121 | |
| 122 | return jsonpointer::basic_json_pointer<char_type>(std::move(tokens)); |
| 123 | } |
| 124 | |
| 125 | enum class op_type {add,remove,replace}; |
| 126 | enum class state_type {begin,abort,commit}; |
no test coverage detected