106 std::string
const &
str()
const {
112 return _path.length();
124 throw std::out_of_range(
"Out of range in path::element(size_t)");
127 return element.second == 0 ?
128 std::string(1,Delim) :
129 _path.substr(element.first,element.second);
151 return *
this == common;
165 segment(
size_t start = 0,
size_t len = std::string::npos)
const {
167 return section.first != std::string::npos ?
168 _path.substr(section.first,section.second) : std::string();
206 _path.insert(0,1,Delim);
219 _path.erase(start,len);
248 return *
this + rhs.
str();
275 after = element.first + element.second + 1;
276 _path.insert(after,str + Delim);
291 void cut(
size_t start = 0,
size_t len = std::string::npos) {
293 if (section.first != std::string::npos) {
294 if (section.first + section.second <
_path.length()) {
296 }
else if (section.first > 0) {
299 _path.erase(section.first,section.second);
310 std::string match(2,Delim);
311 for (
size_t posn ; (
posn =
_path.find(match)) != std::string::npos; ) {
314 size_t len =
_path.length();
315 if (len > 1 &&
_path[len - 1] == Delim) {
316 _path.resize(len - 1);
336 int const &
posn()
const {
359 for (
size_t ndx = 0; ndx < count; ++ndx) {
360 if (rhs[ndx] == lhs[ndx]) {
381 for ( ; (end =
_path.find(Delim,start)) != std::string::npos;
385 if (start <
_path.length()) {
388 if (
_path.length()) {
408 len = std::min(len,
_path.length() - start);
412 len = (last.first + last.second) - first.first;
418 return element_pos(std::string::npos,std::string::npos);
path< Delim > operator+(std::string const &str, path< Delim > const &path)
Get a path by concatenation of a string with a path.
std::string _path
The string representation of the path.
size_t length() const
Get the length of the path.
bool operator==(path const &other) const
Equality.
int _cursor
The cursor of the path.
std::pair< size_t, size_t > element_pos
Type of an element or section locator in a path.
path & operator+=(path const &rhs)
operator+=(path) is equivalent to push_back(path.str())
std::string segment(size_t start=0, size_t len=std::string::npos) const
Get a sub-sequence of the path's elements as a string.
int to_end()
Set the cursor to index the final element, or to 0 if the path is empty.
void pop_front()
Remove the first element of the path, if any.
std::vector< element_pos > _elements
The structure of the path as a sequence of element_pos.
path operator+(std::string const &str) const
Get the concatenation of the path with a string.
void rectify()
Correct anomalies in the path.
std::string const & str() const
Get the path as a string.
char _first
The first character of the path.
bool operator<(path const &other) const
Less-than operator.
void pop_back()
Remove the last element of the path, if any.
bool operator!=(path const &other) const
Inequality.
std::string operator[](size_t which) const
The subscript operator is equivalent to element(which)
path & operator+=(std::string const &str)
operator+=(str) is equivalent to push_back(str)
void analyse()
Analyse the path to determine its composition.
bool is_prefix_of(path const &other) const
Say whether the path consists of an initial subsequence of the elements of another.
std::string cur_element() const
Get the path element at the cursor.
void insert(size_t after, std::string const &str)
Insert a string into the path.
void push_front(std::string const &str)
Prepend a string to the path.
static path common_prefix(path const &lhs, path const &rhs)
Get the common initial prefix of two paths.
element_pos get_section(size_t start, size_t len=std::string::npos) const
Get the location of a section of the path.
size_t elements() const
Get the number of elements in the path
void push_back(std::string const &str)
Append a string to the path.
Encapsulates a filesystem path.
path & operator=(std::string const &str)
Assign from a string.
char _last
The last character of the path.
path(std::string const &path)
Explicitly construct a path from a string.
path operator+(path const &rhs) const
Get the concatenation of the path with another.
std::string element(size_t which) const
Return a path element by index.
void cut(size_t start=0, size_t len=std::string::npos)
Remove a segment from the path.
int & posn()
Get a [const] reference to the path's cursor.