Apache Mesos
Public Member Functions | List of all members
Path Class Reference

Represents a POSIX or Windows file system path and offers common path manipulations. More...

#include <path.hpp>

Public Member Functions

 Path ()
 
 Path (const std::string &path, const char path_separator=os::PATH_SEPARATOR)
 
std::string basename () const
 Extracts the component following the final '/'. More...
 
std::string dirname () const
 Extracts the component up to, but not including, the final '/'. More...
 
Option< std::string > extension () const
 Returns the file extension of the path, including the dot. More...
 
bool absolute () const
 
 operator std::string () const
 
const std::string & string () const
 

Detailed Description

Represents a POSIX or Windows file system path and offers common path manipulations.

When reading the comments below, keep in mind that '/' refers to the path separator character, so read it as "'/' or '\', depending on platform".

Constructor & Destructor Documentation

Path::Path ( )
inline
Path::Path ( const std::string &  path,
const char  path_separator = os::PATH_SEPARATOR 
)
inlineexplicit

Member Function Documentation

bool Path::absolute ( ) const
inline
std::string Path::basename ( ) const
inline

Extracts the component following the final '/'.

Trailing '/' characters are not counted as part of the pathname.

Like the standard '::basename()' except it is thread safe.

The following list of examples (taken from SUSv2) shows the strings returned by basename() for different paths:

path basename
"/usr/lib" "lib"
"/usr/" "usr"
"usr" "usr"
"/" "/"
"." "."
".." ".."
Returns
The component following the final '/'. If Path does not contain a '/', this returns a copy of Path. If Path is the string "/", then this returns the string "/". If Path is an empty string, then it returns the string ".".
std::string Path::dirname ( ) const
inline

Extracts the component up to, but not including, the final '/'.

Trailing '/' characters are not counted as part of the pathname.

Like the standard '::dirname()' except it is thread safe.

The following list of examples (taken from SUSv2) shows the strings returned by dirname() for different paths:

path dirname
"/usr/lib" "/usr"
"/usr/" "/"
"usr" "."
"/" "/"
"." "."
".." "."
Returns
The component up to, but not including, the final '/'. If Path does not contain a '/', then this returns the string ".". If Path is the string "/", then this returns the string "/". If Path is an empty string, then this returns the string ".".
Option<std::string> Path::extension ( ) const
inline

Returns the file extension of the path, including the dot.

Returns None if the basename contains no dots, or consists entirely of dots (i.e. '.', '..').

Examples:

path extension
"a.txt" ".txt"
"a.tar.gz" ".gz"
".bashrc" ".bashrc"
"a" None
"." None
".." None
Path::operator std::string ( ) const
inline
const std::string& Path::string ( ) const
inline

The documentation for this class was generated from the following file: