32#include <initializer_list>
84 using value_type = char ;
85 using string_type = std::string ;
86 #if defined(G_WINDOWS) && !defined(G_ANSI)
87 using iopath_char_type = wchar_t ;
89 using iopath_char_type = char ;
92 Path() noexcept(noexcept(
std::
string())) ;
96 Path( const
std::
string & path ) ;
102 Path( const
char * path ) ;
105 Path( const
Path & path , const
std::
string & tail ) ;
108 Path( const
Path & path , const
std::
string & tail_1 , const
std::
string & tail_2 ) ;
111 Path( const
Path & path , const
std::
string & tail_1 , const
std::
string & tail_2 , const
std::
string & tail_3 ) ;
114 bool empty() const noexcept ;
120 const iopath_char_type *
iopath() const ;
124 const value_type *
cstr() const noexcept ;
162 bool isRoot() const noexcept ;
207 void swap(
Path & other ) noexcept ;
210 bool operator==( const
Path & path ) const noexcept(noexcept(
std::
string().compare(
std::
string()))) ;
213 bool operator!=( const
Path & path ) const noexcept(noexcept(
std::
string().compare(
std::
string()))) ;
231 #if defined(G_WINDOWS) && !defined(G_ANSI)
232 mutable std::wstring m_wstr ;
239 return m_str.empty() ;
251 return m_str.c_str() ;
257 #if defined(G_WINDOWS) && !defined(G_ANSI)
259 return m_wstr.c_str() ;
261 return m_str.c_str() ;
268 std::ostream & operator<<( std::ostream & stream ,
const Path & path )
270 return stream << path.
str() ;
274 Path & operator/=( Path & p ,
const std::string & str )
281 Path operator/(
const Path & p ,
const std::string & str )
283 return Path( p , str ) ;
286 Path & operator+=( Path & ,
const std::string & ) = delete ;
287 Path & operator+(
const Path & ,
const std::string & ) = delete ;
290 void swap( Path & p1 , Path & p2 )
noexcept
static std::wstring widen(std::string_view)
Widens from UTF-8 to UTF-16/UCS-4 wstring.
A Path object represents a file system path.
bool isAbsolute() const noexcept
Returns !isRelative().
Path withoutRoot() const
Returns a path without the root part.
void swap(Path &other) noexcept
Swaps this with other.
static bool less(const Path &a, const Path &b)
Compares two paths, with simple eight-bit lexicographical comparisons of each path component.
bool replace(const std::string_view &from, const std::string_view &to, bool ex_root=false)
Replaces the first occurrence of 'from' with 'to', optionally excluding the root part.
static Path join(const StringArray &parts)
Builds a path from a set of parts.
const value_type * cstr() const noexcept
Returns the path's c-string.
bool isRoot() const noexcept
Returns true if the path is a root, like "/", "c:", "c:/", "\\server\volume" etc.
std::string basename() const
Returns the rightmost part of the path, ignoring "." parts.
Path withoutExtension() const
Returns a path without the basename extension, if any.
Path dirname() const
Returns the path without the rightmost part, ignoring "." parts.
std::string extension() const
Returns the path's basename extension, ie.
bool simple() const
Returns true if the path has a single component (ignoring "." parts), ie.
Path & pathAppend(const std::string &tail)
Appends a filename or a relative path to this path.
static Path nullDevice()
Returns the path of the "/dev/null" special file, or equivalent.
Path() noexcept(noexcept(std::string()))
Default constructor for a zero-length path.
Path withExtension(const std::string &ext) const
Returns the path with the new basename extension.
Path collapsed() const
Returns the path with "foo/.." and "." parts removed, so far as is possible without changing the mean...
bool isRelative() const noexcept
Returns true if the path is a relative path or empty().
static void setPosixStyle()
Sets posix mode for testing purposes.
std::string str() const
Returns the path string.
static void setWindowsStyle()
Sets windows mode for testing purposes.
StringArray split() const
Spits the path into a list of component parts (ignoring "." parts unless the whole path is "....
bool empty() const noexcept
Returns true if the path is empty.
const iopath_char_type * iopath() const
Returns the path's string with a type that is suitable for initialising std::fstreams.
static Path difference(const Path &p1, const Path &p2)
Returns the relative path from p1 to p2.
A class like c++17's std::string_view.
std::vector< std::string > StringArray
A std::vector of std::strings.