27 #include "raul/Symbol.hpp"
28 #include "raul/URI.hpp"
48 class BadPath :
public std::exception {
50 BadPath(
const std::string& path) : _path(path) {}
52 const char* what()
const throw() {
return _path.c_str(); }
80 static bool is_path(
const Raul::URI& uri);
90 Path(
const std::basic_string<char>& path);
97 Path(
const char* cpath);
106 static bool is_valid(
const std::basic_string<char>& path);
108 static bool is_valid_name(
const std::basic_string<char>& name) {
109 return name.length() > 0 && name.find(
"/") == std::string::npos
110 && is_valid(std::string(
"/").append(name));
113 static std::string
pathify(
const std::basic_string<char>& str);
114 static std::string
nameify(
const std::basic_string<char>& str);
118 bool is_root()
const {
return (*
this) ==
root(); }
121 bool is_parent_of(
const Path& child)
const;
123 Path child(
const std::string& s)
const {
125 return base() +
Path(s).chop_scheme().substr(1);
131 return base() + p.chop_scheme().substr(1);
134 Path operator+(
const Path& p)
const {
return child(p); }
142 if ((*
this) !=
root()) {
143 const char* last_slash = strrchr(c_str(),
'/');
145 return last_slash + 1;
157 if ((*
this) ==
root()) {
160 const std::string str(this->str());
161 const size_t first_slash = str.find(
'/');
162 const size_t last_slash = str.find_last_of(
'/');
163 return (first_slash == last_slash) ?
root() : str.substr(0, last_slash);
171 return base() + symbol.c_str();
178 if ((*
this) == base) {
181 assert(length() > base.length());
182 return substr(base.length() - 1);
192 inline const std::string
base()
const {
193 std::string ret = str();
194 if ((*
this) ==
root() && ret[ret.length() - 1] ==
'/')
206 return base().substr(find(
":") + 1);
212 return ( child == parent || (child.length() > parent.length() &&
213 (!std::strncmp(parent.c_str(), child.c_str(), parent.length())
214 && (parent ==
root() || child.str()[parent.length()] ==
'/'))) );
218 inline Path(
bool unchecked,
const URI& uri) :
URI(uri) {}
224 #endif // RAUL_PATH_HPP