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

Function to_basic_string

include/jsoncons_ext/jsonpath/path_node.hpp:269–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 6

json_replaceFunction · 0.70
evaluateMethod · 0.70
selectMethod · 0.70
evaluateMethod · 0.70
to_stringFunction · 0.70
to_wstringFunction · 0.70

Calls 9

from_integerFunction · 0.85
node_kindMethod · 0.80
escape_stringFunction · 0.70
sizeMethod · 0.45
parentMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45
nameMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected