33 path::path(
const std::string& v) : absolute_(false), is_directory_(false) {
35 std::string::const_iterator first = v.begin();
36 if (!
parse(first, v.end(), *
this) || first != v.end())
37 throw std::invalid_argument(
"invalid URI path: \"" + v +
"\"");
51 if (itrhs != rhs.
end())
55 if (itrhs == rhs.
end())
64 throw std::out_of_range(
"attempt to access empty URI path");
69 throw std::out_of_range(
"attempt to access empty URI path");
83 segments_type::reverse_iterator rit =
segments_.rbegin();
84 segments_type::reverse_iterator rend =
segments_.rend();
85 segments_type::const_reverse_iterator ritb = back.
segments_.rbegin();
86 segments_type::const_reverse_iterator rendb = back.
segments_.rend();
88 for (; rit != rend && *rit == *ritb; ++rit)
89 if (++ritb == rendb) {
96 segments_type::iterator it =
segments_.begin();
97 for (; ++rit != rend;)
114 segments_type::const_iterator it =
segments_.begin();
115 segments_type::const_iterator itr = rhs.
segments_.begin();
116 for (;; ++it, ++itr) {
119 int i = it->compare(*itr);
120 if (i < 0)
return true;
121 if (0 < i)
return false;
142 for (segments_type::const_iterator it =
segments_.begin(); it !=
segments_.end(); ++it) {
165 s.erase(s.begin() + s.length()-1);
169 bool parse(std::string::const_iterator& first, std::string::const_iterator last,
path& v, std::string* errs) {
170 std::string::const_iterator f = first;
178 for (; f != last; f++) {
188 e +=
", (" +
convert((
size_t)(f - first)) +
") invalid segment encoding (using as is)";
208 if (errs && !e.empty()) {
211 *errs +=
"URI path: \"" + std::string(first, f) +
"\"" + e;
221 if (s.empty() ||
isspaces(s.c_str()))
std::string string() const
Return path string. Added by Lauro.
std::string encoding() const
Calculate encoded string.
bool operator==(const path &rhs) const
Get number of segments.
void pop_front()
Pop front segment and reset absolute.
const_iterator end() const
Get iterator at end.
bool match_prefix(const path &rhs) const
Test if the given other URI path is a prefix of this.
bool parse(std::string::const_iterator &first, std::string::const_iterator last, authority &v)
Parse URI authority, returning whether found or not and advancing first and setting authority if foun...
static const char SEPARATOR_CHAR
separator ('/')
void clear()
Clear segments and reset absolute and is_directory.
bool empty() const
Test if empty and not absolute.
bool pop_back(const path &back)
Remove the back of the path if it matches the argument (including whether directory or not) and retur...
const std::string & back() const
Get back segment.
segments_type::const_iterator const_iterator
segments const iterator type
bool parse(const traits &ts, std::string::const_iterator &first, std::string::const_iterator last, std::string &comp, char *endc)
Parse the URI componet, returning whether successful and setting the string and end char and advancin...
friend bool TECOMMONEXPORT parse(std::string::const_iterator &first, std::string::const_iterator last, path &v, std::string *errs)
Parse URI path, returning whether found or not and advancing first and setting path if found...
bool isspaces(const char *s)
Test if string is empty or all isspace.
std::string encode(const traits &ts, const std::string &comp)
Encode the URI (sub) component.
const_iterator begin() const
Get iterator at beginning.
const std::string & front() const
Get front segment.
bool operator<(const path &rhs) const
Less operator.
const traits PATH_TRAITS
path traits
bool decode(std::string &s)
Decode the pct-encoded (hex) sequences, if any, return success.
std::string convert(const path &v)
URI path to string.
path & operator+=(const std::string &rhs)
Append unencoded segment and reset is_directory.