59 : path(std::move(path))
65 CanonPath(
const std::vector<std::string> & elems);
77 {
return path.size() <= 1; }
79 explicit operator std::string_view()
const
82 const std::string & abs()
const
91 const static std::string epsilon;
92 return isRoot() ? epsilon : path;
95 const char * c_str()
const
96 {
return path.c_str(); }
98 std::string_view rel()
const
99 {
return ((std::string_view)
path).substr(1); }
101 const char * rel_c_str()
const
103 auto cs = path.c_str();
110 std::string_view remaining;
113 Iterator(std::string_view remaining)
114 : remaining(remaining)
115 , slash(remaining.find(
'/'))
118 bool operator != (
const Iterator &
x)
const
119 {
return remaining.data() !=
x.remaining.data(); }
121 bool operator == (
const Iterator &
x)
const
122 {
return !(*
this !=
x); }
124 const std::string_view operator * ()
const
125 {
return remaining.substr(0, slash); }
129 if (slash == remaining.npos)
130 remaining = remaining.substr(remaining.size());
132 remaining = remaining.substr(slash + 1);
133 slash = remaining.find(
'/');
141 std::optional<CanonPath>
parent()
const;
148 std::optional<std::string_view> dirOf()
const
150 if (isRoot())
return std::nullopt;
151 return ((std::string_view)
path).substr(0,
path.rfind(
'/'));
154 std::optional<std::string_view> baseName()
const
156 if (isRoot())
return std::nullopt;
157 return ((std::string_view) path).substr(path.rfind(
'/') + 1);
161 {
return path ==
x.path; }
164 {
return path !=
x.path; }
174 auto i = path.begin();
175 auto j =
x.path.begin();
176 for ( ;
i != path.end() &&
j !=
x.path.end(); ++
i, ++
j) {
178 if (c_i ==
'/') c_i = 0;
180 if (c_j ==
'/') c_j = 0;
181 if (
auto cmp = c_i <=> c_j; cmp != 0)
return cmp;
183 return (
i != path.end()) <=> (
j !=
x.path.end());
207 void push(std::string_view c);
217 bool isAllowed(
const std::set<CanonPath> & allowed)
const;
228std::ostream & operator << (std::ostream & stream,
const CanonPath &
path);
237 return std::hash<std::string>{}(
s.path);
Definition canon-path.hh:41
bool isWithin(const CanonPath &parent) const
Definition canon-path.cc:45
void pop()
Definition canon-path.cc:39
std::string makeRelative(const CanonPath &path) const
Definition canon-path.cc:120
auto operator<=>(const CanonPath &x) const
Definition canon-path.hh:172
const std::string & absOrEmpty() const
Definition canon-path.hh:89
CanonPath operator/(const CanonPath &x) const
Definition canon-path.cc:71
bool isAllowed(const std::set< CanonPath > &allowed) const
Definition canon-path.cc:93
void push(std::string_view c)
Definition canon-path.cc:78
CanonPath(std::string_view raw)
Definition canon-path.cc:15
void extend(const CanonPath &x)
Definition canon-path.cc:62
PosIdx end
Definition lexer.l:5814
std::optional< CanonPath > parent() const
auto i
Definition lexer.l:2745
return s
Definition lexer.l:459
T x
Definition lexer.l:2648
CanonPath(std::string_view raw)
ExprAttrs::AttrDefs::iterator j
Definition lexer.l:8572
std::string path
Definition lexer.l:1399
Definition canon-path.hh:109
Definition canon-path.hh:56