LeviLamina
Loading...
Searching...
No Matches
PathView.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
8#include "mc/deps/core/file/Path.h"
9
10// auto generated forward declare list
11// clang-format off
12namespace Core { class Path; }
13// clang-format on
14
15namespace Core {
16
17class PathView {
18public:
19 ~PathView() = default;
20
21 PathView(const PathView& other) = default;
22 PathView& operator=(const PathView& other) = default;
23
24 PathView(PathView&& other) noexcept = default;
25 PathView& operator=(PathView&& other) noexcept = default;
26
27 explicit PathView(const std::string& s) : mSrc(s) {}
28 explicit PathView(const char* s) : mSrc(s ? s : "") {}
29 explicit PathView(std::string_view s) : mSrc(s) {}
30
31 PathView(const Core::Path& src) : mSrc(src.getUtf8StdString()) {}
32
33 [[nodiscard]] size_t size() const { return mSrc.size(); }
34 [[nodiscard]] bool empty() const { return mSrc.empty(); }
35
36 [[nodiscard]] std::string_view getUtf8StringView() const { return mSrc; }
37 [[nodiscard]] const char* getUtf8CString() const { return mSrc.data(); }
38
39 [[nodiscard]] bool isAbsolute() const {
40#ifdef _WIN32
41 if (mSrc.size() >= 2 && std::isalpha((unsigned char)mSrc[0]) && mSrc[1] == ':') return true;
42 if (mSrc.size() >= 2 && mSrc[0] == '\\' && mSrc[1] == '\\') return true;
43 return false;
44#else
45 return !mSrc.empty() && mSrc.front() == '/';
46#endif
47 }
48
49private:
50 std::string_view mSrc;
51};
52
53} // namespace Core
Definition Path.h:10