![]() |
Plasma Engine
2.0
|
Contains Helper functions to work with paths. More...
#include <PathUtils.h>
Static Public Member Functions | |
static bool | IsPathSeparator (plUInt32 c) |
Returns whether c is any known path separator. | |
static bool | IsValidFilenameChar (plUInt32 uiCharacter) |
Checks if a given character is allowed in a filename (not path!) | |
static bool | ContainsInvalidFilenameChars (plStringView sPath) |
Checks every character in the string with IsValidFilenameChar() | |
static const char * | FindPreviousSeparator (const char *szPathStart, const char *szStartSearchAt) |
Searches for the previous path separator before szStartSearchAt. Will return nullptr if it reaches szPathStart before finding any separator. | |
static bool | HasAnyExtension (plStringView sPath) |
Checks whether the given path has any file extension. | |
static bool | HasExtension (plStringView sPath, plStringView sExtension) |
Checks whether the path ends with the given file extension. szExtension may or may not start with a dot. The check is case insensitive. | |
static plStringView | GetFileExtension (plStringView sPath, bool bFullExtension=false) |
Returns the file extension of the given path. Will be empty, if the path does not end with a proper extension. The dot (.) is not included. | |
static plStringView | GetFileName (plStringView sPath, bool bRemoveFullExtension=false) |
Returns the file name of a path, excluding the path and extension. | |
static plStringView | GetFileNameAndExtension (plStringView sPath) |
Returns the substring that represents the file name including the file extension. | |
static plStringView | GetFileDirectory (plStringView sPath) |
Returns the directory of the given file, which is the substring up to the last path separator. | |
static bool | IsAbsolutePath (plStringView sPath) |
Returns true, if the given path represents an absolute path on the current OS. | |
static bool | IsRelativePath (plStringView sPath) |
Returns true, if the given path represents a relative path on the current OS. | |
static bool | IsRootedPath (plStringView sPath) |
A rooted path starts with a colon and then names a file-system data directory. Rooted paths are used as 'absolute' paths within the plFileSystem. | |
static void | GetRootedPathParts (plStringView sPath, plStringView &ref_sRoot, plStringView &ref_sRelPath) |
Splits the passed path into its root portion and the relative path. | |
static plStringView | GetRootedPathRootName (plStringView sPath) |
Special case of GetRootedPathParts that returns the root of the input path and discards the relative path. | |
static void | MakeValidFilename (plStringView sFilename, plUInt32 uiReplacementCharacter, plStringBuilder &out_sFilename) |
Creates a valid filename (not path!) using the given string by replacing all disallowed characters. | |
static bool | IsSubPath (plStringView sPrefixPath, plStringView sFullPath) |
Checks whether sFullPath starts with sPrefixPath. | |
static bool | IsSubPath_NoCase (plStringView sPrefixPath, plStringView sFullPath) |
Checks whether sFullPath starts with sPrefixPath. Case insensitive. | |
Static Public Attributes | |
static const char | OsSpecificPathSeparator |
The path separator used by this operating system. | |
Contains Helper functions to work with paths.
Only functions that require read-only access to a string are provided here All functions that require to modify the path are provided by plStringBuilder. Many functions return plStringView's, which will always be strict sub-strings of their input data. That allows that these functions can work without any additional memory allocations.
|
static |
Checks every character in the string with IsValidFilenameChar()
This is a basic check, only because each character passes the test, it does not guarantee that the full string is a valid path.
|
static |
Returns the directory of the given file, which is the substring up to the last path separator.
If the path already ends in a path separator, and thus points to a folder, instead of a file, the unchanged path is returned. "path/to/file" -> "path/to/" "path/to/folder/" -> "path/to/folder/" "filename" -> "" "/file_at_root_level" -> "/"
|
static |
Returns the file extension of the given path. Will be empty, if the path does not end with a proper extension. The dot (.) is not included.
If bFullExtension is false, a file named "file.a.b.c" will return "c". If bFullExtension is true, a file named "file.a.b.c" will return "a.b.c".
|
static |
Returns the file name of a path, excluding the path and extension.
If the path already ends with a path separator, the result will be empty.
|
static |
Returns the substring that represents the file name including the file extension.
Returns an empty string, if sPath already ends in a path separator, or is empty itself.
|
static |
Splits the passed path into its root portion and the relative path.
":MyRoot\file.txt" -> root = "MyRoot", relPath="file.txt" ":MyRoot\folder\file.txt" -> root = "MyRoot", relPath = "folder\file.txt" ":\MyRoot\folder\file.txt" -> root = "MyRoot", relPath = "folder\file.txt" ":/MyRoot\folder\file.txt" -> root = "MyRoot", relPath = "folder\file.txt" If the path is not rooted, then root will be an empty string and relPath is set to the full input path.
|
static |
Checks whether the path ends with the given file extension. szExtension may or may not start with a dot. The check is case insensitive.
HasExtension("file.txt", "txt") -> true HasExtension("file.txt", ".txt") -> true HasExtension("file.a.b", ".b") -> true HasExtension("file.a.b", "a.b") -> true HasExtension("file.a.b", ".a.b") -> true HasExtension("file.a.b", "file.a.b") -> false
|
static |
Checks if a given character is allowed in a filename (not path!)
|
static |
Creates a valid filename (not path!) using the given string by replacing all disallowed characters.
Note that path separators in the given string will be replaced as well! Asserts that replacementCharacter is an allowed character.