plptools
Loading...
Searching...
No Matches
pathutils Namespace Reference

Conveniences for working with paths. More...

Enumerations

enum class  PathFormat { kPOSIX = 0 , kWindows = 1 , kHost = kPOSIX , kEPOC = kWindows }
 

Functions

char path_separator (const PathFormat format)
 
std::string epoc_basename (std::string path)
 Returns the last path component of an EPOC path. More...
 
char * epoc_dirname (const char *path)
 Compute parent directory of an EPOC directory. More...
 
char * resolve_epoc_path (const char *path, const char *initialPath)
 Returns a new absolute EPOC path, determined by resolving path relative to initialPath. More...
 
std::vector< std::string > split (const std::string &path, const PathFormat format)
 Split a path, path, into its components, using the path separator, separator. More...
 
std::string join (const std::vector< std::string > &components, const PathFormat format)
 Return a new path by joining the path components, components, with path separator, separator. More...
 
bool is_absolute (const std::string &path, const PathFormat format)
 Check if a path is absolute. More...
 
std::string appending_components (const std::string &path, const std::vector< std::string > &components, const PathFormat format)
 Convenience wrapper for join that returns a new path resulting from appending path components, components, to path, path, using separator, separator. More...
 
std::string resolve_path (const std::string &path, const std::string &startingPath, const PathFormat format)
 Returns a path by resolving a relative or absolute path against a starting path. More...
 

Detailed Description

Conveniences for working with paths.

These methods currently have a mishmash of C and C++ as they're a collection of various utilities from around plptools. Hopefully they can be unified in the future.

Enumeration Type Documentation

◆ PathFormat

enum class pathutils::PathFormat
strong
Enumerator
kPOSIX 
kWindows 
kHost 
kEPOC 

Definition at line 38 of file pathutils.h.

Function Documentation

◆ appending_components()

std::string pathutils::appending_components ( const std::string &  path,
const std::vector< std::string > &  components,
const PathFormat  format 
)

Convenience wrapper for join that returns a new path resulting from appending path components, components, to path, path, using separator, separator.

Parameters
pathBase path to append components to.
componentsComponents to append to path.
formatPath format.
Returns
String containing the resulting path.

Definition at line 215 of file pathutils.cc.

◆ epoc_basename()

std::string pathutils::epoc_basename ( std::string  path)

Returns the last path component of an EPOC path.

If the path doesn't contain any EPOC path separators (\), the returned string matches the path.

Definition at line 83 of file pathutils.cc.

◆ epoc_dirname()

char * pathutils::epoc_dirname ( const char *  path)

Compute parent directory of an EPOC directory.

Definition at line 91 of file pathutils.cc.

◆ is_absolute()

bool pathutils::is_absolute ( const std::string &  path,
const PathFormat  format 
)

Check if a path is absolute.

For a Windows path to be absolute, it must be both fully qualified (with a drive), and rooted (with a leading path separator.

Parameters
pathPath to test.
formatPath format.
Returns
true if the path, path, is absolute; false otherwise.

Definition at line 223 of file pathutils.cc.

◆ join()

std::string pathutils::join ( const std::vector< std::string > &  components,
const PathFormat  format 
)

Return a new path by joining the path components, components, with path separator, separator.

For absolute paths, the first path component should be a root component (e.g., '/' or 'C:').

Empty strings indicate an intentional directory marker. These are valid anywhere, but have no effect and are therefore ignored unless they occur at the end of the path where they cause the returned path to have a trailing separator. If a path comprises only a single empty string component (directory marker) then the returned path will be the relative path '.' followed by the relevant separator.

Parameters
componentsPath components to join.
formatPath format.
Returns
String containing the resulting path.

Definition at line 179 of file pathutils.cc.

◆ path_separator()

char pathutils::path_separator ( const PathFormat  format)

Definition at line 74 of file pathutils.cc.

◆ resolve_epoc_path()

char * pathutils::resolve_epoc_path ( const char *  path,
const char *  initialPath 
)

Returns a new absolute EPOC path, determined by resolving path relative to initialPath.

If path is already an absolute path, this returns path.

Definition at line 116 of file pathutils.cc.

◆ resolve_path()

std::string pathutils::resolve_path ( const std::string &  path,
const std::string &  startingPath,
const PathFormat  format 
)

Returns a path by resolving a relative or absolute path against a starting path.

startingPath may be relative or absolute, but path must be contained within that path.

Definition at line 262 of file pathutils.cc.

◆ split()

std::vector< std::string > pathutils::split ( const std::string &  path,
const PathFormat  format 
)

Split a path, path, into its components, using the path separator, separator.

If the path is absolute, the first element of the path separator will represent the root component appropriate to the path type (POSIX or Windows) as implied by the path separator (e.g., '/' or 'C:').

If the path ends in a trailing separator, the returned vector will contain a last empty string component as an intentional marker.

Parameters
pathPath to split.
formatPath format.
Returns
Vector containing the path components.

Definition at line 142 of file pathutils.cc.