Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
StringPath.h
1// Copyright (c) Stefano Cristiano
2// SPDX-License-Identifier: MIT
3#pragma once
4#include "../Foundation/StringSpan.h"
5
6namespace SC
7{
10{
12#if SC_PLATFORM_WINDOWS
13 static constexpr size_t MaxPath = 260; // Equal to 'MAX_PATH' on Windows
14#elif SC_PLATFORM_APPLE
15 static constexpr size_t MaxPath = 1024; // Equal to 'PATH_MAX' on macOS
16#else
17 static constexpr size_t MaxPath = 4096; // Equal to 'PATH_MAX' on Linux
18#endif
19 size_t length = 0;
20#if SC_PLATFORM_WINDOWS
21 wchar_t path[MaxPath];
22 operator StringSpan() const { return StringSpan({path, length}, true); }
23#else
24 char path[MaxPath];
25 operator StringSpan() const { return StringSpan({path, length}, true, StringEncoding::Utf8); }
26#endif
27
29 [[nodiscard]] StringSpan view() const { return *this; }
30
32 [[nodiscard]] bool assign(StringSpan pathToConvert);
33};
34} // namespace SC
Pre-sized char array holding enough space to represent a file system path.
Definition StringPath.h:10
size_t length
Length of the path in bytes (excluding null terminator)
Definition StringPath.h:19
static constexpr size_t MaxPath
Maximum size of paths on current native platform.
Definition StringPath.h:17
bool assign(StringSpan pathToConvert)
Assigns a StringView to current StringPath, converting the encoding from UTF16 to UTF8 if needed.
StringSpan view() const
Obtain a StringSpan from the current StringPath.
Definition StringPath.h:29
char path[MaxPath]
Native path on Posix (UTF-8)
Definition StringPath.h:24
An read-only view over a string (to avoid including Strings library when parsing is not needed).
Definition StringSpan.h:31