| 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()) |
| 270 | { |
| 271 | std::basic_string<CharT,std::char_traits<CharT>,Allocator> buffer(alloc); |
| 272 | |
| 273 | using path_node_type = basic_path_node<CharT>; |
| 274 | |
| 275 | std::vector<const path_node_type*> nodes(path.size(), nullptr); |
| 276 | std::size_t len = nodes.size(); |
| 277 | const path_node_type* p = std::addressof(path); |
| 278 | while (p != nullptr) |
| 279 | { |
| 280 | nodes[--len] = p; |
| 281 | p = p->parent(); |
| 282 | } |
| 283 | |
| 284 | for (auto node : nodes) |
| 285 | { |
| 286 | switch (node->node_kind()) |
| 287 | { |
| 288 | case path_node_kind::root: |
| 289 | buffer.push_back('$'); |
| 290 | break; |
| 291 | case path_node_kind::name: |
| 292 | buffer.push_back('['); |
| 293 | buffer.push_back('\''); |
| 294 | jsoncons::jsonpath::escape_string(node->name().data(), node->name().size(), buffer); |
| 295 | buffer.push_back('\''); |
| 296 | buffer.push_back(']'); |
| 297 | break; |
| 298 | case path_node_kind::index: |
| 299 | buffer.push_back('['); |
| 300 | jsoncons::from_integer(node->index(), buffer); |
| 301 | buffer.push_back(']'); |
| 302 | break; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | return buffer; |
| 307 | } |
| 308 | |
| 309 | using path_node = basic_path_node<char>; |
| 310 | using wpath_node = basic_path_node<wchar_t>; |
no test coverage detected