4#include "../Foundation/Internal/IGrowableBuffer.h"
5#include "../Strings/StringView.h"
6#include "StringsExport.h"
16struct SC_STRINGS_EXPORT
Path
23#if SC_PLATFORM_WINDOWS
32 bool endsWithSeparator =
false;
84 StringView separator = SeparatorStringView(),
bool skipEmpty =
false)
86 return join(GrowableBuffer<T>{output}, GrowableBuffer<T>::getEncodingFor(output), inputs, separator, skipEmpty);
89 [[nodiscard]]
static bool join(IGrowableBuffer&& output, StringEncoding encoding,
Span<const StringView> inputs,
90 StringView separator = SeparatorStringView(),
bool skipEmpty =
false);
168 static const char Separator =
'\\';
170 [[nodiscard]]
static constexpr StringView SeparatorStringView() {
return "\\"_a8; };
175 static const char Separator =
'/';
177 [[nodiscard]]
static constexpr StringView SeparatorStringView() {
return "/"_a8; }
181#if SC_PLATFORM_WINDOWS
182 static constexpr char Separator =
'\\';
184 static constexpr char Separator =
'/';
188#if SC_PLATFORM_WINDOWS
189 [[nodiscard]]
static constexpr StringView SeparatorStringView() {
return "\\"_a8; };
206 template <
typename T,
int numComponents = 64>
210 return normalize(GrowableBuffer<T>{output}, output.getEncoding(), view, type, components);
213 [[nodiscard]]
static bool normalize(IGrowableBuffer&& output, StringEncoding encoding,
StringView view, Type type,
230 template <
typename T>
232 Type outputType = AsNative)
234 return relativeFromTo(GrowableBuffer<T>{output}, output.getEncoding(), source, destination, type, outputType);
237 [[nodiscard]]
static bool relativeFromTo(IGrowableBuffer&& output, StringEncoding encoding,
StringView source,
238 StringView destination, Type type, Type outputType = AsNative);
245 template <
typename T>
248 return append(GrowableBuffer<T>{output}, GrowableBuffer<T>::getEncodingFor(output), paths, inputType);
251 [[nodiscard]]
static bool append(IGrowableBuffer&& output, StringEncoding encoding,
Span<const StringView> paths,
Holds the various parsed components of a path.
Definition Path.h:31
StringView root
Ex. "C:\\"</tt> on windows - <tt>"/" on posix.
Definition Path.h:37
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:39
StringView name
Ex. "name" for "C:\\dir\\name.ext" on windows or "/dir/name.ext" on posix.
Definition Path.h:40
StringView ext
Ex. "ext" for "C:\\dir\\name.ext" on windows or "/dir/name.ext" on posix.
Definition Path.h:41
StringView directory
Ex. "C:\\dir" on windows - "/dir" on posix.
Definition Path.h:38
bool parsePosix(StringView input)
Parses all components on posix input path.
Parse and compose filesystem paths for windows and posix.
Definition Path.h:17
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:83
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:191
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:231
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:246
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:207
Type
Path type (windows or posix)
Definition Path.h:20
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:47