userver: userver/formats/common/path.hpp Source File
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&& parent, std::string_view key);
25
26std::string MakeChildPath(std::string_view parent, std::size_t index);
27std::string MakeChildPath(std::string&& parent, std::size_t index);
28
29/// @ingroup userver_universal
30///
31/// Document/array element path storage
32class Path {
33 public:
34 Path();
35
36 bool IsRoot() const;
37 std::string ToString() const;
38 std::string_view ToStringView() const;
39
40 Path MakeChildPath(std::string_view key) const;
41 Path MakeChildPath(std::size_t index) const;
42
43 static Path WithPrefix(std::string path_prefix);
44
45 private:
46 explicit Path(std::string path);
47
48 std::string path_;
49};
50
51} // namespace formats::common
52
53USERVER_NAMESPACE_END