Github   Telegram
Loading...
Searching...
No Matches
path.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/formats/common/path.hpp
4/// @brief @copybrief formats::common::Path
5
6#include <string>
7#include <string_view>
8
9USERVER_NAMESPACE_BEGIN
10
11namespace formats::common {
12
13inline constexpr char kPathSeparator = '.';
14inline constexpr char kPathRoot[] = "/";
15inline constexpr char kPathPrefixSeparator[] = ":/";
16
17/// Returns string of [idx], e.g. "[0]" or "[1025]"
18std::string GetIndexString(size_t index);
19
20void AppendPath(std::string& path, std::string_view key);
21void AppendPath(std::string& path, std::size_t index);
22
23std::string MakeChildPath(std::string_view parent, std::string_view key);
24std::string MakeChildPath(std::string_view parent, std::size_t index);
25
26/// Document/array element path storage
27class Path {
28 public:
29 Path();
30
31 bool IsRoot() const;
32 std::string ToString() const;
33 std::string_view ToStringView() const;
34
35 Path MakeChildPath(std::string_view key) const;
36 Path MakeChildPath(std::size_t index) const;
37
38 static Path WithPrefix(std::string path_prefix);
39
40 private:
41 explicit Path(std::string path);
42
43 std::string path_;
44};
45
46} // namespace formats::common
47
48USERVER_NAMESPACE_END