4#include "../Foundation/Internal/IGrowableBuffer.h"
5#include "../Strings/StringView.h"
15struct SC_COMPILER_EXPORT
Path
22#if SC_PLATFORM_WINDOWS
31 bool endsWithSeparator =
false;
83 StringView separator = SeparatorStringView(),
bool skipEmpty =
false)
85 return join(GrowableBuffer<T>{output}, output.getEncoding(), inputs, separator, skipEmpty);
88 [[nodiscard]]
static bool join(IGrowableBuffer&& output, StringEncoding encoding,
Span<const StringView> inputs,
89 StringView separator = SeparatorStringView(),
bool skipEmpty =
false);
167 static const char Separator =
'\\';
169 [[nodiscard]]
static constexpr StringView SeparatorStringView() {
return "\\"_a8; };
174 static const char Separator =
'/';
176 [[nodiscard]]
static constexpr StringView SeparatorStringView() {
return "/"_a8; }
180#if SC_PLATFORM_WINDOWS
181 static constexpr char Separator =
'\\';
183 static constexpr char Separator =
'/';
187#if SC_PLATFORM_WINDOWS
188 [[nodiscard]]
static constexpr StringView SeparatorStringView() {
return "\\"_a8; };
205 template <
typename T,
int numComponents = 64>
209 return normalize(GrowableBuffer<T>{output}, output.getEncoding(), view, type, components);
212 [[nodiscard]]
static bool normalize(IGrowableBuffer&& output, StringEncoding encoding,
StringView view, Type type,
229 template <
typename T>
231 Type outputType = AsNative)
233 return relativeFromTo(GrowableBuffer<T>{output}, output.getEncoding(), source, destination, type, outputType);
236 [[nodiscard]]
static bool relativeFromTo(IGrowableBuffer&& output, StringEncoding encoding,
StringView source,
237 StringView destination, Type type, Type outputType = AsNative);
244 template <
typename T>
247 return append(GrowableBuffer<T>{output}, output.getEncoding(), paths, inputType);
250 [[nodiscard]]
static bool append(IGrowableBuffer&& output, StringEncoding encoding,
Span<const StringView> paths,
265 template <
typename T>
269 return normalizeUNCAndTrimQuotes(GrowableBuffer<T>{outputPath}, outputPath.getEncoding(), fileLocation, type,
272 [[nodiscard]]
static bool normalizeUNCAndTrimQuotes(IGrowableBuffer&& outputPath, StringEncoding encoding,
Holds the various parsed components of a path.
Definition Path.h:30
StringView root
Ex. "C:\\"</tt> on windows - <tt>"/" on posix.
Definition Path.h:36
bool parseWindows(StringView input)
Parses all components on windows input path.
StringView base
Ex. "base" for "C:\\dir\\base" on windows or "/dir/base" on posix.
Definition Path.h:38
StringView name
Ex. "name" for "C:\\dir\\name.ext" on windows or "/dir/name.ext" on posix.
Definition Path.h:39
StringView ext
Ex. "ext" for "C:\\dir\\name.ext" on windows or "/dir/name.ext" on posix.
Definition Path.h:40
StringView directory
Ex. "C:\\dir" on windows - "/dir" on posix.
Definition Path.h:37
bool parsePosix(StringView input)
Parses all components on posix input path.
Parse and compose filesystem paths for windows and posix.
Definition Path.h:16
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.
Definition Path.h:82
static StringView basename(StringView input, StringView suffix)
Returns the base name of a path.
static bool parseNameExtension(const StringView input, StringView &name, StringView &extension)
Splits a StringView of type "name.ext" into "name" and "ext".
static StringView removeStartingSeparator(StringView path)
Return a path without its (potential) starting separator.
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 constexpr StringView SeparatorStringView()
Path separator StringView for current platform.
Definition Path.h:190
static bool relativeFromTo(T &output, StringView source, StringView destination, Type type, Type outputType=AsNative)
Get relative path that appended to source resolves to destination.
Definition Path.h:230
static bool endsWithSeparator(StringView path)
Check if the path ends with a Windows or Posix separator.
static bool append(T &output, Span< const StringView > paths, Type inputType)
Append to an existing path a series of StringView with a separator.
Definition Path.h:245
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...
Definition Path.h:266
static StringView basename(StringView input, Type type)
Returns the base name of a path.
static bool normalize(T &output, StringView view, Type type)
Resolves all .. to output a normalized path String.
Definition Path.h:206
Type
Path type (windows or posix)
Definition Path.h:19
static bool isAbsolute(StringView input, Type type)
Checks if a path is absolute.
View over a contiguous sequence of items (pointer + size in elements).
Definition Span.h:29
Non-owning view over a range of characters with UTF Encoding.
Definition StringView.h:46