#include <bdls_pathutil.h>
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 bdls_pathutil
|
| 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) |
| |
◆ appendIfValid() [1/2]
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
- Note that any filesystem separator characters at the end of
filename or path will be discarded. See Terminology for the definition of separator.
◆ appendIfValid() [2/2]
| static int bdls::PathUtil::appendIfValid |
( |
std::string * |
path, |
|
|
const bsl::string_view & |
filename |
|
) |
| |
|
static |
◆ appendRaw() [1/2]
| static void bdls::PathUtil::appendRaw |
( |
bsl::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.
- Precondition
- 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 .
◆ appendRaw() [2/2]
| static void bdls::PathUtil::appendRaw |
( |
std::string * |
path, |
|
|
const char * |
filename, |
|
|
int |
length = -1, |
|
|
int |
rootEnd = -1 |
|
) |
| |
|
static |
◆ getBasename() [1/2]
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
- Note that
getBasename is a synonym for getLeaf. See Parsing and Performance . See also Terminology for the definition of leaf and root.
◆ getBasename() [2/2]
| int bdls::PathUtil::getBasename |
( |
std::string * |
leaf, |
|
|
const bsl::string_view & |
path, |
|
|
int |
rootEnd = -1 |
|
) |
| |
|
inlinestatic |
◆ getDirname() [1/2]
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
- 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 . See also Terminology for the definition of directories and root.
◆ getDirname() [2/2]
| static int bdls::PathUtil::getDirname |
( |
std::string * |
dirname, |
|
|
const bsl::string_view & |
path, |
|
|
int |
rootEnd = -1 |
|
) |
| |
|
static |
◆ getExtension() [1/2]
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 . See also [](Terminology) for the definition of leaf and root.
◆ getExtension() [2/2]
| static int bdls::PathUtil::getExtension |
( |
std::string * |
extension, |
|
|
const bsl::string_view & |
path, |
|
|
int |
rootEnd = -1 |
|
) |
| |
|
static |
◆ getLeaf() [1/2]
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
- Note that
getBasename is a synonym for getLeaf. See Parsing and Performance . See also Terminology for the definition of leaf and root.
◆ getLeaf() [2/2]
| static int bdls::PathUtil::getLeaf |
( |
std::string * |
leaf, |
|
|
const bsl::string_view & |
path, |
|
|
int |
rootEnd = -1 |
|
) |
| |
|
static |
◆ getRoot() [1/2]
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
- Note that the meaning of the root part is platform-dependent. See Parsing and Performance . See also [](Terminology) for the definition of root.
◆ getRoot() [2/2]
| static int bdls::PathUtil::getRoot |
( |
std::string * |
root, |
|
|
const bsl::string_view & |
path, |
|
|
int |
rootEnd = -1 |
|
) |
| |
|
static |
◆ getRootEnd()
Return the 0-based position in the specified path of the character following the root.
- Note
- Note that a return value of 0 indicates a relative path. See Parsing and Performance . See also [](Terminology) for the definition of root.
◆ hasLeaf()
| 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 . See also Terminology for the definition of root.
◆ isAbsolute()
| 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 . See also Terminology for the definition of root.
◆ isRelative()
| 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 . See also Terminology for the definition of root.
◆ popLeaf() [1/2]
| static int bdls::PathUtil::popLeaf |
( |
bsl::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 . See also Terminology for the definition of leaf and root.
◆ popLeaf() [2/2]
| static int bdls::PathUtil::popLeaf |
( |
std::string * |
path, |
|
|
int |
rootEnd = -1 |
|
) |
| |
|
static |
◆ splitFilename()
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.
- Precondition
- The behavior is undefined unless
head != tail and INT_MAX >= path.length().
- Note
- Note that
head or tail may point to the path object when the method is called.
◆ k_SEPARATOR
| const char bdls::PathUtil::k_SEPARATOR |
|
static |
The documentation for this struct was generated from the following file: