IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
path_utils.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/string.hxx>
6#include <ice/heap_string.hxx>
8
9namespace ice::path
10{
14
17
19 auto length(ice::String path) noexcept -> ice::u32;
20
23
26
29
33
38 auto join(ice::HeapString<>& path, ice::String right_path) noexcept -> ice::String;
39
46
50
57
58 // Wide character implementations
59
62 auto length(ice::WString path) noexcept -> ice::u32;
67
72
73 template<ice::concepts::StringType StringT>
74 using Path = typename StringT::PathType;
75
76} // namespace ice::path
77
78namespace ice
79{
80
82 {
83 template<typename Self>
84 bool is_absolute(this Self const& self) noexcept
85 {
86 return ice::path::is_absolute(self);
87 }
88
89 template<typename Self>
90 bool is_relative(this Self const& self) noexcept
91 {
92 return self.is_absolute() == false;
93 }
94
95 template<typename Self>
96 constexpr auto extension(this Self const& self) noexcept -> ice::string::String<Self>
97 {
98 return ice::path::extension(self);
99 }
100
101 template<typename Self>
102 constexpr auto filename(this Self const& self) noexcept -> ice::string::String<Self>
103 {
104 return ice::path::filename(self);
105 }
106
107 template<typename Self>
108 constexpr auto basename(this Self const& self) noexcept -> ice::string::String<Self>
109 {
110 return ice::path::basename(self);
111 }
112
113 template<typename Self>
114 constexpr auto directory(this Self const& self) noexcept -> ice::path::Path<Self>
115 {
117 }
118 };
119
121 {
122 template<typename Self>
123 auto join(this Self& self, ice::path::Path<Self> other) noexcept -> ice::path::Path<Self>
124 {
125 return ice::path::Path<Self>{ ice::path::join(self, other) };
126 }
127
128 template<typename Self>
129 auto normalize(this Self& self) noexcept -> ice::path::Path<Self>
130 {
132 }
133
134 template<typename Self>
139
140 template<typename Self>
145 };
146
147 template<ice::concepts::SupportedCharType CharT>
148 struct BasicPath : public ice::BasicString<CharT>, public ice::PathString
149 {
150 using BasicString<CharT>::BasicString;
151 using BasicString<CharT>::operator std::basic_string_view<CharT>;
153
154 constexpr BasicPath(ice::BasicString<CharT> str) noexcept
155 : BasicString<CharT>{ str }
156 {}
157 };
158
159 template<ice::concepts::SupportedCharType CharT>
160 struct BasicHeapPath : public ice::HeapString<CharT>, public ice::HeapPathString
161 {
162 using HeapString<CharT>::HeapString;
163 using HeapString<CharT>::operator ice::BasicString<CharT>;
164 using HeapString<CharT>::operator =;
166
167 constexpr operator ice::BasicPath<CharT>() const noexcept { return { this->data(), this->size() }; }
168 };
169
172
173 template<typename CharT>
175 {
176 return ice::hash(ice::String{ path });
177 }
178
179 template<typename CharT>
181 {
182 return ice::hash(ice::String{ path });
183 }
184
185} // namespace
186
187
188template<>
189struct fmt::formatter<ice::BasicPath<char>> : public fmt::formatter<std::basic_string_view<char>>
190{
191 template<typename FormatContext>
192 constexpr auto format(ice::BasicPath<char> value, FormatContext& ctx) const noexcept
193 {
194 return fmt::formatter<std::basic_string_view<char>>::format(value, ctx);
195 }
196};
197
198template<>
199struct fmt::formatter<ice::BasicHeapPath<char>> : public fmt::formatter<ice::BasicPath<char>>
200{
201 template<typename FormatContext>
202 constexpr auto format(ice::BasicHeapPath<char> value, FormatContext& ctx) const noexcept
203 {
204 return fmt::formatter<ice::BasicPath<char>>::format(value, ctx);
205 }
206};
Definition path_utils.hxx:10
auto replace_extension(ice::HeapString<> &path, ice::String extension) noexcept -> ice::String
Replaces the extension (if any) in the path.
auto length(ice::String path) noexcept -> ice::u32
auto directory(ice::String path) noexcept -> ice::String
auto join(ice::HeapString<> &path, ice::String right_path) noexcept -> ice::String
Joins two paths together if possible, the result is stored in the first first variable.
auto extension(ice::String path) noexcept -> ice::String
typename StringT::PathType Path
Definition path_utils.hxx:74
auto basename(ice::String path) noexcept -> ice::String
auto replace_filename(ice::HeapString<> &path, ice::String filename) noexcept -> ice::String
Replaces the filename of in the path. (including the extension).
bool is_absolute_root(ice::String path) noexcept
auto normalize(ice::HeapString<> &path) noexcept -> ice::String
Normalizes the given path in using simple rules.
bool is_absolute(ice::String path) noexcept
auto filename(ice::String path) noexcept -> ice::String
typename StringT::StringType String
Definition string_concepts.hxx:64
SPDX-License-Identifier: MIT.
Definition array.hxx:12
ice::BasicString< char > String
Definition string.hxx:82
ice::BasicString< wchar_t > WString
Definition string.hxx:83
ice::BasicPath< char > Path
Definition path_utils.hxx:170
std::uint32_t u32
Definition types.hxx:26
constexpr auto hash(ice::HeapString<> const &value) noexcept -> ice::u64
Definition heap_string.hxx:251
ice::BasicHeapPath< char > HeapPath
Definition path_utils.hxx:171
constexpr auto format(ice::BasicHeapPath< char > value, FormatContext &ctx) const noexcept
Definition path_utils.hxx:202
constexpr auto format(ice::BasicPath< char > value, FormatContext &ctx) const noexcept
Definition path_utils.hxx:192
Definition path_utils.hxx:161
ice::BasicPath< CharT > PathType
Definition path_utils.hxx:165
Definition path_utils.hxx:149
ice::BasicPath< CharT > PathType
Definition path_utils.hxx:152
constexpr BasicPath(ice::BasicString< CharT > str) noexcept
Definition path_utils.hxx:154
Definition string.hxx:15
constexpr BasicString() noexcept=default
Definition path_utils.hxx:121
auto normalize(this Self &self) noexcept -> ice::path::Path< Self >
Definition path_utils.hxx:129
auto replace_extension(this Self &self, ice::string::String< Self > extension) noexcept -> ice::path::Path< Self >
Definition path_utils.hxx:141
auto replace_filename(this Self &self, ice::string::String< Self > filename) noexcept -> ice::path::Path< Self >
Definition path_utils.hxx:135
auto join(this Self &self, ice::path::Path< Self > other) noexcept -> ice::path::Path< Self >
Definition path_utils.hxx:123
Definition heap_string.hxx:15
auto size() const noexcept -> SizeType
Definition heap_string.hxx:46
auto data(this Self &self) noexcept -> ValueType *
Definition heap_string.hxx:44
HeapString(ice::Allocator &allocator) noexcept
Definition heap_string.hxx:57
Definition path_utils.hxx:82
constexpr auto filename(this Self const &self) noexcept -> ice::string::String< Self >
Definition path_utils.hxx:102
bool is_absolute(this Self const &self) noexcept
Definition path_utils.hxx:84
bool is_relative(this Self const &self) noexcept
Definition path_utils.hxx:90
constexpr auto extension(this Self const &self) noexcept -> ice::string::String< Self >
Definition path_utils.hxx:96
constexpr auto directory(this Self const &self) noexcept -> ice::path::Path< Self >
Definition path_utils.hxx:114
constexpr auto basename(this Self const &self) noexcept -> ice::string::String< Self >
Definition path_utils.hxx:108