| 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()) |
no test coverage detected