Parse and compose filesystem paths for windows and posix. More...
#include <Path.h>
Classes | |
| struct | ParsedView |
| Holds the various parsed components of a path. More... | |
| struct | Posix |
| struct | Windows |
Public Types | |
| enum | Type { AsPosix , AsWindows , AsNative = AsPosix } |
| Path type (windows or posix) More... | |
Static Public Member Functions | |
| template<typename T > | |
| static bool | join (T &output, Span< const StringView > inputs, StringView separator=SeparatorStringView(), bool skipEmpty=false) |
| Joins multiple StringView with a Separator into an output String. | |
| static bool | join (IGrowableBuffer &&output, StringEncoding encoding, Span< const StringView > inputs, StringView separator=SeparatorStringView(), bool skipEmpty=false) |
| static bool | parseNameExtension (const StringView input, StringView &name, StringView &extension) |
| Splits a StringView of type "name.ext" into "name" and "ext". | |
| static bool | parse (StringView input, Path::ParsedView &pathView, Type type) |
| Splits a Posix or Windows path into a ParsedView. | |
| static StringView | dirname (StringView input, Type type, int repeat=0) |
| Returns the directory name of a path. | |
| static StringView | basename (StringView input, Type type) |
| Returns the base name of a path. | |
| static StringView | basename (StringView input, StringView suffix) |
| Returns the base name of a path. | |
| static bool | isAbsolute (StringView input, Type type) |
| Checks if a path is absolute. | |
| static constexpr StringView | SeparatorStringView () |
| Path separator StringView for current platform. | |
| template<typename T , int numComponents = 64> | |
| static bool | normalize (T &output, StringView view, Type type) |
Resolves all .. to output a normalized path String. | |
| static bool | normalize (IGrowableBuffer &&output, StringEncoding encoding, StringView view, Type type, Span< StringView > components) |
| template<typename T > | |
| static bool | relativeFromTo (T &output, StringView source, StringView destination, Type type, Type outputType=AsNative) |
Get relative path that appended to source resolves to destination. | |
| static bool | relativeFromTo (IGrowableBuffer &&output, StringEncoding encoding, StringView source, StringView destination, Type type, Type outputType=AsNative) |
| template<typename T > | |
| static bool | append (T &output, Span< const StringView > paths, Type inputType) |
| Append to an existing path a series of StringView with a separator. | |
| static bool | append (IGrowableBuffer &&output, StringEncoding encoding, Span< const StringView > paths, Type inputType) |
| static bool | endsWithSeparator (StringView path) |
| Check if the path ends with a Windows or Posix separator. | |
| static StringView | removeStartingSeparator (StringView path) |
| Return a path without its (potential) starting separator. | |
| template<typename T > | |
| static bool | normalizeUNCAndTrimQuotes (T &outputPath, StringView fileLocation, Type type, Span< StringView > components) |
| An extended Path::normalize handling a bug with incorrect FILE backslash escape on Windows when using UNC Paths, and also removing quote characters '"' added when passing such paths to compiler command line. | |
| static bool | normalizeUNCAndTrimQuotes (IGrowableBuffer &&outputPath, StringEncoding encoding, StringView fileLocation, Type type, Span< StringView > components) |
Static Public Attributes | |
| static constexpr char | Separator = '/' |
| Path separator char for current platform. | |
Parse and compose filesystem paths for windows and posix.
| enum SC::Path::Type |
Path type (windows or posix)
|
inlinestaticnodiscard |
Append to an existing path a series of StringView with a separator.
| [out] | output | The destination string containing the existing path, that will be extended |
| [in] | paths | The path components to join, appended to output |
| [in] | inputType | Specify to append as Windows or Posix path components |
true if the output path can joined properly
|
staticnodiscard |
Returns the base name of a path.
Suffix is stripped if existing. Trailing separators are ignored.
For example:
| [in] | input | The StringView with path to be parsed. Trailing separators are ignored. |
| [in] | suffix | The StringView extension (or suffix in general) to strip if existing. |
input holding the base name
|
staticnodiscard |
Returns the base name of a path.
Trailing separators are ignored.
For example:
| [in] | input | The StringView with path to be parsed. Trailing separators are ignored. |
| [in] | type | Specify to parse as Windows or Posix path |
input holding the base name
|
staticnodiscard |
Returns the directory name of a path.
Trailing separators are ignored.
For example:
| [in] | input | The StringView with path to be parsed. Trailing separators are ignored. |
| [in] | type | Specify to parse as Windows or Posix path |
| [in] | repeat | how many directory levels should be removed dirname("/1/2/3/4", Path::AsPosix, 1) == "/1/2" |
input holding the directory name
|
staticnodiscard |
|
staticnodiscard |
Checks if a path is absolute.
For example:
| [in] | input | The StringView with path to be parsed. Trailing separators are ignored. |
| [in] | type | Specify to parse as Windows or Posix path |
true if input is absolute
|
inlinestaticnodiscard |
Joins multiple StringView with a Separator into an output String.
| [out] | output | The output string receiving the path |
| [in] | inputs | The input paths to join |
| [in] | separator | The separator to use. By default / on Posix and \ on Windows |
| [in] | skipEmpty | If true will skip empty entries in inputs Span |
|
inlinestaticnodiscard |
Resolves all .. to output a normalized path String.
For example:
| [out] | output | Reference to String that will receive the normalized Path |
| [in] | view | The path to be normalized (but it should not be a view() of the output String) |
| [in] | type | Specify to parse as Windows or Posix path |
true if the Path was successfully parsed and normalized
|
inlinestaticnodiscard |
An extended Path::normalize handling a bug with incorrect FILE backslash escape on Windows when using UNC Paths, and also removing quote characters '"' added when passing such paths to compiler command line.
|
staticnodiscard |
Splits a Posix or Windows path into a ParsedView.
| [in] | input | The StringView with path to be parsed |
| [out] | pathView | The output parsed ParsedView with all components of path |
| [in] | type | Specify to parse as Windows or Posix path |
true if path was parsed successfully
|
staticnodiscard |
Splits a StringView of type "name.ext" into "name" and "ext".
| [in] | input | An input filename (ex. "name.ext") |
| [out] | name | Output string holding name ("name" in "name.ext") |
| [out] | extension | Output string holding extension ("ext" in "name.ext") |
false if both name and extension will be empty after trying to parse themExample:
|
inlinestaticnodiscard |
Get relative path that appended to source resolves to destination.
For example:
| [out] | output | The output relative path computed that transforms source into destination |
| [in] | source | The source Path |
| [in] | destination | The destination Path |
| [in] | type | Specify to parse as Windows or Posix path |
| [in] | outputType | Specify if the output relative path should be formatted as a Posix or Windows path |
true if source and destination paths can be properly parsed as absolute paths
|
staticnodiscard |
Return a path without its (potential) starting separator.
| [in] | path | The path to use |
|
inlinestaticnodiscardconstexpr |
Path separator StringView for current platform.
|
staticconstexpr |
Path separator char for current platform.