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

Function select

include/jsoncons_ext/jsonpath/path_node.hpp:227–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225
226 template <typename Json>
227 Json* select(Json& root, const basic_path_node<typename Json::char_type>& path)
228 {
229 using path_node_type = basic_path_node<typename Json::char_type>;
230
231 std::vector<const path_node_type*> nodes(path.size(), nullptr);
232 std::size_t len = nodes.size();
233 const path_node_type* p = std::addressof(path);
234 while (p != nullptr)
235 {
236 nodes[--len] = p;
237 p = p->parent();
238 }
239
240 Json* current = std::addressof(root);
241 for (auto node : nodes)
242 {
243 if (node->node_kind() == path_node_kind::index)
244 {
245 if (current->type() != json_type::array || node->index() >= current->size())
246 {
247 return nullptr;
248 }
249 current = std::addressof(current->at(node->index()));
250 }
251 else if (node->node_kind() == path_node_kind::name)
252 {
253 if (current->type() != json_type::object)
254 {
255 return nullptr;
256 }
257 auto it = current->find(node->name());
258 if (it == current->object_range().end())
259 {
260 return nullptr;
261 }
262 current = std::addressof((*it).value());
263 }
264 }
265 return current;
266 }
267
268 template <typename CharT,typename Allocator=std::allocator<CharT>>
269 std::basic_string<CharT,std::char_traits<CharT>,Allocator> to_basic_string(const basic_path_node<CharT>& path, const Allocator& alloc=Allocator())

Callers 8

selectMethod · 0.85
evaluateMethod · 0.85
evaluateMethod · 0.85
selectMethod · 0.85
evaluateMethod · 0.85
evaluateMethod · 0.85
evaluateMethod · 0.85
evaluateMethod · 0.85

Calls 10

node_kindMethod · 0.80
typeMethod · 0.80
atMethod · 0.80
sizeMethod · 0.45
parentMethod · 0.45
indexMethod · 0.45
findMethod · 0.45
nameMethod · 0.45
endMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected