Quick Links:

bal | bbl | bdl | bsl

Static Public Member Functions

bdls::PathUtil Struct Reference

#include <bdls_pathutil.h>

List of all members.

Static Public Member Functions

static int appendIfValid (bsl::string *path, const bsl::string_view &filename)
static int appendIfValid (std::string *path, const bsl::string_view &filename)
static void appendRaw (bsl::string *path, const char *filename, int length=-1, int rootEnd=-1)
static void appendRaw (std::string *path, const char *filename, int length=-1, int rootEnd=-1)
static int popLeaf (bsl::string *path, int rootEnd=-1)
static int popLeaf (std::string *path, int rootEnd=-1)
static int getBasename (bsl::string *leaf, const bsl::string_view &path, int rootEnd=-1)
static int getBasename (std::string *leaf, const bsl::string_view &path, int rootEnd=-1)
static int getDirname (bsl::string *dirname, const bsl::string_view &path, int rootEnd=-1)
static int getDirname (std::string *dirname, const bsl::string_view &path, int rootEnd=-1)
static int getLeaf (bsl::string *leaf, const bsl::string_view &path, int rootEnd=-1)
static int getLeaf (std::string *leaf, const bsl::string_view &path, int rootEnd=-1)
static int getExtension (bsl::string *extension, const bsl::string_view &path, int rootEnd=-1)
static int getExtension (std::string *extension, const bsl::string_view &path, int rootEnd=-1)
static int getRoot (bsl::string *root, const bsl::string_view &path, int rootEnd=-1)
static int getRoot (std::string *root, const bsl::string_view &path, int rootEnd=-1)
static void splitFilename (bsl::string_view *head, bsl::string_view *tail, const bsl::string_view &path, int rootEnd=-1)
static bool isAbsolute (const bsl::string_view &path, int rootEnd=-1)
static bool isRelative (const bsl::string_view &path, int rootEnd=-1)
static bool hasLeaf (const bsl::string_view &path, int rootEnd=-1)
static int getRootEnd (const bsl::string_view &path)

Detailed Description

This struct contains utility methods for platform-independent manipulation of filesystem paths. No method of this struct provides any filesystem operations or accesses the filesystem as part of its implementation.

See Component bdls_pathutil


Member Function Documentation

static int bdls::PathUtil::appendIfValid ( bsl::string path,
const bsl::string_view &  filename 
) [static]
static int bdls::PathUtil::appendIfValid ( std::string *  path,
const bsl::string_view &  filename 
) [static]

Append the specified filename to the end of the specified path if filename represents a relative path. Return 0 on success, and a non-zero value otherwise. Note that any filesystem separator characters at the end of filename or path will be discarded. See Terminology for the definition of separator.

static void bdls::PathUtil::appendRaw ( bsl::string path,
const char *  filename,
int  length = -1,
int  rootEnd = -1 
) [static]
static void bdls::PathUtil::appendRaw ( std::string *  path,
const char *  filename,
int  length = -1,
int  rootEnd = -1 
) [static]

Append the specified filename up to the optionally specified length to the end of the specified path. If length is negative, append the entire string. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. The behavior is undefined if filename represents an absolute path or if either filename or path ends with the filesystem separator character. The behavior is also undefined if filename points to any part of path (i.e., filename may not be an alias for path). See Parsing and Performance (rootEnd argument).

static int bdls::PathUtil::popLeaf ( bsl::string path,
int  rootEnd = -1 
) [static]
static int bdls::PathUtil::popLeaf ( std::string *  path,
int  rootEnd = -1 
) [static]

Remove from the specified path the rightmost filename following the root; that is, remove the leaf element. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. Return 0 on success, and a nonzero value otherwise; in particular, return a nonzero value if path does not have a leaf. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of leaf and root.

static int bdls::PathUtil::getBasename ( bsl::string leaf,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]
static int bdls::PathUtil::getBasename ( std::string *  leaf,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Load into the specified leaf the value of the rightmost name in the specified path that follows the root; that is, the leaf element. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. Return 0 on success, and a non-zero value otherwise; in particular, return nonzero if path does not have a leaf. Note that getBasename is a synonym for getLeaf. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of leaf and root.

static int bdls::PathUtil::getDirname ( bsl::string dirname,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]
static int bdls::PathUtil::getDirname ( std::string *  dirname,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Load into the specified dirname the value of the directory part of the specified path, that is, the root if it exists and all the filenames except the last one (the leaf). If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. Return 0 on success, and a non-zero value otherwise; in particular, return a nonzero value if path does not have a leaf. Note that in the case of a relative path with a single filename, the function will succeed and dirname will be the empty string. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of directories and root.

static int bdls::PathUtil::getLeaf ( bsl::string leaf,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]
static int bdls::PathUtil::getLeaf ( std::string *  leaf,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Load into the specified leaf the value of the rightmost name in the specified path that follows the root; that is, the leaf element. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. Return 0 on success, and a non-zero value otherwise; in particular, return nonzero if path does not have a leaf. Note that getBasename is a synonym for getLeaf. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of leaf and root.

static int bdls::PathUtil::getExtension ( bsl::string extension,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]
static int bdls::PathUtil::getExtension ( std::string *  extension,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Load into the specified extension the extension of path. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. Return 0 if the path has an extension, and a non-zero value otherwise. See Parsing and Performance (rootEnd argument). See also Terminology for the definitions of extension and root.

static int bdls::PathUtil::getRoot ( bsl::string root,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]
static int bdls::PathUtil::getRoot ( std::string *  root,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Load into the specified root the value of the root part of the specified path. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. Return 0 on success, and a non-zero value otherwise; in particular, return a nonzero value if path is relative. Note that the meaning of the root part is platform-dependent. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of root.

static void bdls::PathUtil::splitFilename ( bsl::string_view *  head,
bsl::string_view *  tail,
const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Load the last pathname component from the specified path into the specified tail and everything leading up to that to the specified head. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. The tail part never contains a slash; if path ends in a slash, tail is empty. If there is no slash in path, head is empty. If path is empty, both head and tail are empty. Trailing slashes are stripped from head unless it is the root.

          +------------------+------------+---------+
          |      PATH        |    HEAD    |   TAIL  |
          +==================+============+=========+
          | "one"            | ""         | "one"   |
          +------------------+------------+---------+
          | "/one/two/three" | "/one/two" | "three" |
          +------------------+------------+---------+
          | "//one/two///"   | "/one/two" | ""      |
          +------------------+------------+---------+
          | "c:\\one\\two"   | "c:\\one"  | "two"   |
          +------------------+------------+---------+

See Terminology for the definition of root. The behavior is undefined unless head != tail and INT_MAX >= path.length(). Note that head or tail may point to the path object when the method is called.

static bool bdls::PathUtil::isAbsolute ( const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Return true if the specified path is absolute (has a root), and false otherwise. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of root.

static bool bdls::PathUtil::isRelative ( const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Return true if the specified path is relative (lacks a root), and false otherwise. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of root.

static bool bdls::PathUtil::hasLeaf ( const bsl::string_view &  path,
int  rootEnd = -1 
) [static]

Return true if the specified path has a filename following the root, and false otherwise. If the optionally specified rootEnd offset is non-negative, it is taken as the position in path of the character following the root. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of leaf.

static int bdls::PathUtil::getRootEnd ( const bsl::string_view &  path  )  [static]

Return the 0-based position in the specified path of the character following the root. Note that a return value of 0 indicates a relative path. See Parsing and Performance (rootEnd argument). See also Terminology for the definition of root.


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