LeviLamina
Loading...
Searching...
No Matches
Path.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/core/file/PathBuffer.h"
7#include "mc/deps/core/string/BasicStackString.h"
8
9namespace Core {
10
11class Path : public ::Core::PathBuffer<::std::string> {
12public:
14
15 Path() = default;
16
17 Path(std::filesystem::path const& path) : Path(path.u8string()) {}
18 Path(std::u8string&& path) { value = std::move(*reinterpret_cast<std::string*>(&path)); }
19 Path(std::string&& path) { value = std::move(path); }
20 Path(std::u8string const& path) { value = *reinterpret_cast<std::string const*>(&path); }
21 Path(std::string const& path) { value = path; }
22 Path(char const* path) { value = path; }
23
24 Path(Path const& other) = default;
25
26 Path(Path&& other) noexcept : Base{std::move(other.value)} {}
27
28 Path& operator=(Path const& other) {
29 if (this != &other) value = other.value;
30 return *this;
31 }
32
33 Path& operator=(Path&& other) noexcept {
34 if (this != &other) value = std::move(other.value);
35 return *this;
36 }
37
38 bool operator<(Path const& rhs) const noexcept { return value < rhs.value; }
39
40 bool operator==(Path const& rhs) const noexcept { return value == rhs.value; }
41
42 [[nodiscard]] char const* getUtf8CString() const noexcept { return value.c_str(); }
43
44 [[nodiscard]] std::string_view getUtf8StringView() const noexcept { return value; }
45
46 [[nodiscard]] std::string const& getUtf8StdString() const noexcept { return value; }
47
48 [[nodiscard]] size_t size() const noexcept { return value.size(); }
49
50 [[nodiscard]] bool empty() const noexcept { return value.empty(); }
51
52 [[nodiscard]] bool isAbsolute() const noexcept {
53#ifdef _WIN32
54 auto const& s = value;
55 if (s.size() >= 2 && std::isalpha(static_cast<unsigned char>(s[0])) && s[1] == ':') return true;
56 if (s.size() >= 2 && s[0] == '\\' && s[1] == '\\') return true;
57 return false;
58#else
59 auto const& s = value;
60 return !s.empty() && s.front() == '/';
61#endif
62 }
63
64 [[nodiscard]] bool isDotOrDotDot() const noexcept { return value == "." || value == ".."; }
65
66 // Static constant EMPTY
67 static Path const& EMPTY() {
68 static Path const emptyPath("");
69 return emptyPath;
70 }
71};
72
73} // namespace Core
Definition PathBuffer.h:8