XII Release 0.1.0
Loading...
Searching...
No Matches
xiiPathUtils Class Reference

Contains Helper functions to work with paths. More...

#include <PathUtils.h>

Static Public Member Functions

static bool IsPathSeparator (xiiUInt32 c)
 Returns whether c is any known path separator.
 
static bool IsValidFilenameChar (xiiUInt32 uiCharacter)
 Checks if a given character is allowed in a filename (not path!)
 
static bool ContainsInvalidFilenameChars (xiiStringView 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 (xiiStringView sPath)
 Checks whether the given path has any file extension.
 
static bool HasExtension (xiiStringView sPath, xiiStringView 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 xiiStringView GetFileExtension (xiiStringView 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 xiiStringView GetFileName (xiiStringView sPath, bool bRemoveFullExtension=false)
 Returns the file name of a path, excluding the path and extension.
 
static xiiStringView GetFileNameAndExtension (xiiStringView sPath)
 Returns the substring that represents the file name including the file extension.
 
static xiiStringView GetFileDirectory (xiiStringView sPath)
 Returns the directory of the given file, which is the substring up to the last path separator.
 
static bool IsAbsolutePath (xiiStringView sPath)
 Returns true, if the given path represents an absolute path on the current OS.
 
static bool IsRelativePath (xiiStringView sPath)
 Returns true, if the given path represents a relative path on the current OS.
 
static bool IsRootedPath (xiiStringView 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 xiiFileSystem.
 
static void GetRootedPathParts (xiiStringView sPath, xiiStringView &ref_sRoot, xiiStringView &ref_sRelPath)
 Splits the passed path into its root portion and the relative path.
 
static xiiStringView GetRootedPathRootName (xiiStringView sPath)
 Special case of GetRootedPathParts that returns the root of the input path and discards the relative path.
 
static void MakeValidFilename (xiiStringView sFilename, xiiUInt32 uiReplacementCharacter, xiiStringBuilder &out_sFilename)
 Creates a valid filename (not path!) using the given string by replacing all disallowed characters.
 
static bool IsSubPath (xiiStringView sPrefixPath, xiiStringView sFullPath)
 Checks whether sFullPath starts with sPrefixPath.
 
static bool IsSubPath_NoCase (xiiStringView sPrefixPath, xiiStringView sFullPath)
 Checks whether sFullPath starts with sPrefixPath. Case insensitive.
 

Static Public Attributes

static const char OsSpecificPathSeparator = XII_PLATFORM_PATH_SEPARATOR
 The path separator used by this operating system.
 

Detailed Description

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 xiiStringBuilder. Many functions return xiiStringView's, which will always be strict sub-strings of their input data. That allows that these functions can work without any additional memory allocations.

Member Function Documentation

◆ ContainsInvalidFilenameChars()

bool xiiPathUtils::ContainsInvalidFilenameChars ( xiiStringView sPath)
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.

Test
Not tested yet

◆ GetFileDirectory()

xiiStringView xiiPathUtils::GetFileDirectory ( xiiStringView sPath)
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" -> "/"

◆ GetFileExtension()

xiiStringView xiiPathUtils::GetFileExtension ( xiiStringView sPath,
bool bFullExtension = false )
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".

◆ GetFileName()

xiiStringView xiiPathUtils::GetFileName ( xiiStringView sPath,
bool bRemoveFullExtension = false )
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.

◆ GetFileNameAndExtension()

xiiStringView xiiPathUtils::GetFileNameAndExtension ( xiiStringView sPath)
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.

◆ GetRootedPathParts()

void xiiPathUtils::GetRootedPathParts ( xiiStringView sPath,
xiiStringView & ref_sRoot,
xiiStringView & ref_sRelPath )
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.

◆ HasExtension()

bool xiiPathUtils::HasExtension ( xiiStringView sPath,
xiiStringView sExtension )
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

◆ IsValidFilenameChar()

bool xiiPathUtils::IsValidFilenameChar ( xiiUInt32 uiCharacter)
static

Checks if a given character is allowed in a filename (not path!)

Test
Not tested yet

◆ MakeValidFilename()

void xiiPathUtils::MakeValidFilename ( xiiStringView sFilename,
xiiUInt32 uiReplacementCharacter,
xiiStringBuilder & out_sFilename )
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.

See also
IsValidFilenameChar()

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