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