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