27 #include <raul/Symbol.hpp>
46 class Path :
public std::basic_string<char> {
50 Path() : std::basic_string<char>(
"/") {}
57 Path(
const std::basic_string<char>& path)
58 : std::basic_string<char>(path)
60 assert(is_valid(path));
70 : std::basic_string<char>(cpath)
72 assert(is_valid(cpath));
75 static bool is_valid(
const std::basic_string<char>& path);
77 static bool is_valid_name(
const std::basic_string<char>&
name) {
78 return name.length() > 0 && is_valid(std::string(
"/").append(name));
81 static std::string pathify(
const std::basic_string<char>& str);
82 static std::string nameify(
const std::basic_string<char>& str);
84 static void replace_invalid_chars(std::string& str,
bool replace_slash =
false);
87 bool is_parent_of(
const Path& child)
const;
97 return substr(find_last_of(
"/")+1);
107 std::basic_string<char>
parent = substr(0, find_last_of(
"/"));
108 return (parent ==
"") ?
"/" :
parent;
115 if ((*
this) == base) {
118 assert(length() > base.length());
119 return substr(base.length());
129 inline const std::string
base()
const {
133 return (*
this) +
"/";
138 return ( child == parent || (child.length() > parent.length() &&
139 (!std::strncmp(parent.c_str(), child.c_str(), parent.length())
140 && (parent ==
"/" || child[parent.length()] ==
'/'))) );
147 #endif // RAUL_PATH_HPP
Simple wrapper around standard string with useful path-specific methods.
Definition: Path.hpp:46
Path(const std::basic_string< char > &path)
Construct a Path from an std::string.
Definition: Path.hpp:57
const std::string base() const
Return path with a trailing "/".
Definition: Path.hpp:129
static bool descendant_comparator(const Path &parent, const Path &child)
Return true if child is equal to, or a descendant of parent.
Definition: Path.hpp:137
Path parent() const
Return the parent's path.
Definition: Path.hpp:106
Symbol name() const
Return the name of this object (everything after the last '/').
Definition: Path.hpp:93
Path()
Construct an uninitialzed path, because the STL is annoying.
Definition: Path.hpp:50
A restricted string (C identifier, which is a component of a path).
Definition: Symbol.hpp:36
Path(const char *cpath)
Construct a Path from a C string.
Definition: Path.hpp:69
Path relative_to_base(const Path &base) const
Return path relative to soe base path (chop prefix)
Definition: Path.hpp:114