Returns a view of the node matching a fully-qualified "TOML path".
\detail \cpp auto config = toml::parse(R"(
[foo]
bar = [ 0, 1, 2, [ 3 ], { kek = 4 } ]
)"sv);
toml::path path1("foo.bar[2]"); toml::path path2("foo.bar[4].kek"); std::cout << toml::at_path(config, path1) << "\n"; std::cout << toml::at_path(config, path1.parent_path()) << "\n"; std::cout << toml::at_path(config, path2) << "\n"; std::cout << toml::at_path(config, path2.parent_path()) << "\n"; \ecpp
\out 2 [ 0, 1, 2, [ 3 ], { kek = 4 } ] 4 { kek = 4 } \eout
- Note
- Keys in paths are interpreted literally, so whitespace (or lack thereof) matters: \cpp toml::at_path(config, toml::path("foo.bar")) // same as config["foo"]["bar"] toml::at_path(config, toml::path("foo. bar")) // same as config["foo"][" bar"] toml::at_path(config, toml::path("foo..bar")) // same as config["foo"][""]["bar"] toml::at_path(config, toml::path(".foo.bar")) // same as config[""]["foo"]["bar"] \ecpp
Additionally, TOML allows '.' (period) characters to appear in keys if they are quoted strings. This function makes no allowance for this, instead treating all period characters as sub-table delimiters.
- Parameters
-
root | The root node from which the path will be traversed. |
path | The "TOML path" to traverse. |