MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / definite_path

Function definite_path

include/jsoncons_ext/jsonpatch/jsonpatch.hpp:88–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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};

Callers 1

apply_patchFunction · 0.85

Calls 9

from_integerFunction · 0.85
getFunction · 0.50
rbeginMethod · 0.45
rendMethod · 0.45
beginMethod · 0.45
baseMethod · 0.45
push_backMethod · 0.45
is_arrayMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected