Thea
Static Public Member Functions | List of all members
FilePath Class Reference

Operations on file paths. More...

#include <FilePath.hpp>

Static Public Member Functions

static std::string baseName (std::string const &path)
 Get the basename of the object, consisting of the object name without the path, upto but not including the first period character. More...
 
static std::string changeCompleteExtension (std::string const &path, std::string const &new_ext)
 Change the complete extension of a path. More...
 
static std::string changeExtension (std::string const &path, std::string const &new_ext)
 Change the extension of a path. More...
 
static std::string completeBaseName (std::string const &path)
 Get the complete basename of the object, consisting of the object name without the path, upto but not including the last period character. More...
 
static std::string completeExtension (std::string const &path)
 Get the complete extension of the object, consisting of all characters after the first period character (or null if no period exists). More...
 
static std::string concat (std::string const &parent, std::string const &child)
 Get the full path to a child object, given the path to the containing directory and the name of the child itself. More...
 
static std::string extension (std::string const &path)
 Get the extension of the object, consisting of all characters after the last period character (or null if no period exists). More...
 
static std::string getRelative (std::string const &path, std::string const &ref_dir)
 Get the path of an object relative to a reference directory. More...
 
static bool isAbsolute (std::string const &path)
 Returns true if a path uniquely identifies a file or directory. More...
 
static bool isRelative (std::string const &path)
 Returns true if a path does not uniquely identify a file or directory. More...
 
static std::string objectName (std::string const &path)
 Get the name of the object without the path. More...
 
static std::string parent (std::string const &path)
 Get the path to the immediate parent of an object. More...
 

Detailed Description

Operations on file paths.

These do string manipulation and do not actually access the filesystem.

Note
Returned paths are in native OS format (e.g. backslashes on Windows, forward slashes on Unix).
Trailing slashes at the end of directory names, and repeated slashes, are ignored, so "/foo" and "/foo/" are treated identically, as are "foo/bar" and "foo///bar". In this respect this implementation differs from, say, Boost.Filesystem.
Beware of the distinction between extensions and complete extensions (and by symmetry, complete base names and base names). "foo.old.txt" has extension "txt", complete extension "old.txt", complete base name "foo.old", and base name "foo".

Definition at line 31 of file FilePath.hpp.

Member Function Documentation

std::string baseName ( std::string const &  path)
static

Get the basename of the object, consisting of the object name without the path, upto but not including the first period character.

In other words, this returns path minus completeExtension(path).

See also
completeBaseName()

Definition at line 21 of file FilePath.cpp.

std::string changeCompleteExtension ( std::string const &  path,
std::string const &  new_ext 
)
static

Change the complete extension of a path.

Equivalent to concat(parent(path), baseName(path) + "." + new_ext). Examples:

changeExtension("foo.txt", "dat") // produces "foo.dat"
changeExtension("foo.old.txt", "dat") // produces "foo.dat"
Parameters
pathThe path to change.
new_extThe new complete extension.
See also
completeExtension(), changeExtension()

Definition at line 97 of file FilePath.cpp.

std::string changeExtension ( std::string const &  path,
std::string const &  new_ext 
)
static

Change the extension of a path.

Equivalent to concat(parent(path), completeBaseName(path) + "." + new_ext). Examples:

changeExtension("foo.txt", "dat") // produces "foo.dat"
changeExtension("foo.old.txt", "dat") // produces "foo.old.dat"
Parameters
pathThe path to change.
new_extThe new extension.
See also
extension(), changeCompleteExtension()

Definition at line 91 of file FilePath.cpp.

std::string completeBaseName ( std::string const &  path)
static

Get the complete basename of the object, consisting of the object name without the path, upto but not including the last period character.

In other words, this returns path minus extension(path).

See also
baseName()

Definition at line 29 of file FilePath.cpp.

std::string completeExtension ( std::string const &  path)
static

Get the complete extension of the object, consisting of all characters after the first period character (or null if no period exists).

Definition at line 45 of file FilePath.cpp.

std::string concat ( std::string const &  parent,
std::string const &  child 
)
static

Get the full path to a child object, given the path to the containing directory and the name of the child itself.

If the directory name is empty, just the child name is returned.

Definition at line 83 of file FilePath.cpp.

std::string extension ( std::string const &  path)
static

Get the extension of the object, consisting of all characters after the last period character (or null if no period exists).

Definition at line 37 of file FilePath.cpp.

std::string getRelative ( std::string const &  path,
std::string const &  ref_dir 
)
static

Get the path of an object relative to a reference directory.

Parameters
pathThe path to be made relative.
ref_dirThe path to the reference directory.
Note
This function does not do any transformations that would involve touching the filesystem, such as resolving symlinks or checking if files/directories exist.

Definition at line 115 of file FilePath.cpp.

bool isAbsolute ( std::string const &  path)
static

Returns true if a path uniquely identifies a file or directory.

Definition at line 103 of file FilePath.cpp.

bool isRelative ( std::string const &  path)
static

Returns true if a path does not uniquely identify a file or directory.

Definition at line 109 of file FilePath.cpp.

std::string objectName ( std::string const &  path)
static

Get the name of the object without the path.

Ignores trailing slashes and isolated period characters.

Definition at line 53 of file FilePath.cpp.

std::string parent ( std::string const &  path)
static

Get the path to the immediate parent of an object.

Ignores trailing slashes and isolated period characters.

Definition at line 68 of file FilePath.cpp.


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