Skip to content

Commit a035729

Browse files
author
Julian LALU
committed
Improve unicode support
1 parent 0369d36 commit a035729

File tree

23 files changed

+1786
-1540
lines changed

23 files changed

+1786
-1540
lines changed

interface/core/allocators/memory_allocation.h

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ namespace hud
8686
*/
8787
HD_FORCEINLINE constexpr memory_allocation &operator=(memory_allocation &&other) noexcept
8888
{
89-
if (this != &other) [[likely]]
90-
{
89+
if (this != &other) [[likely]] {
9190
begin_ptr_ = other.begin_ptr_;
9291
other.begin_ptr_ = nullptr;
9392
end_ptr_ = other.end_ptr_;
@@ -128,13 +127,24 @@ namespace hud
128127
{
129128
return begin_ptr_;
130129
}
130+
/** Retrieves a pointer to the beginning of the sequence. */
131+
[[nodiscard]] HD_FORCEINLINE constexpr const type_t *data_const() const noexcept
132+
{
133+
return begin_ptr_;
134+
}
131135

132136
/** Retrieves a pointer to the end of the sequence. */
133137
[[nodiscard]] HD_FORCEINLINE constexpr type_t *data_end() const noexcept
134138
{
135139
return end_ptr_;
136140
}
137141

142+
/** Retrieves a pointer to the end of the sequence. */
143+
[[nodiscard]] HD_FORCEINLINE constexpr const type_t *data_end_const() const noexcept
144+
{
145+
return end_ptr_;
146+
}
147+
138148
/**
139149
* Retrieves a pointer to the element at the given `index` of the sequence.
140150
* A special case is allowed when `data_at(count())` is called.
@@ -193,23 +203,40 @@ namespace hud
193203
}
194204

195205
/** Convert the allocation to a slice. */
196-
[[nodiscard]] HD_FORCEINLINE constexpr slice<type_t> to_slice() const noexcept
206+
[[nodiscard]] HD_FORCEINLINE constexpr slice<const type_t> as_slice() const noexcept
197207
{
198-
return slice(begin_ptr_, count());
208+
return slice(data_const(), count());
209+
}
210+
/** Convert the allocation to a slice. */
211+
[[nodiscard]] HD_FORCEINLINE constexpr slice<type_t> as_slice() noexcept
212+
{
213+
return slice(data(), count());
199214
}
200215

201-
/** Retrieves an iterator_type to the beginning of the slice. */
202-
[[nodiscard]] HD_FORCEINLINE constexpr iterator_type begin() const noexcept
216+
/** Retrieves an iterator_type to the beginning of the allocation. */
217+
[[nodiscard]] HD_FORCEINLINE constexpr iterator_type begin() noexcept
203218
{
204219
return iterator_type(begin_ptr_);
205220
}
206221

207-
/** Retrieves an iterator_type to the end of the slice. */
208-
[[nodiscard]] HD_FORCEINLINE constexpr iterator_type end() const noexcept
222+
/** Retrieves an const_iterator_type to the beginning of the allocation. */
223+
[[nodiscard]] HD_FORCEINLINE constexpr const_iterator_type begin() const noexcept
224+
{
225+
return const_iterator_type(begin_ptr_);
226+
}
227+
228+
/** Retrieves an iterator_type to the end of the allocation. */
229+
[[nodiscard]] HD_FORCEINLINE constexpr iterator_type end() noexcept
209230
{
210231
return iterator_type(end_ptr_);
211232
}
212233

234+
/** Retrieves an const_iterator_type to the end of the allocation. */
235+
[[nodiscard]] HD_FORCEINLINE constexpr const_iterator_type end() const noexcept
236+
{
237+
return const_iterator_type(end_ptr_);
238+
}
239+
213240
private:
214241
memory_allocation(const memory_allocation &) = delete;
215242
memory_allocation &operator=(const memory_allocation &) = delete;

interface/core/character/character.h

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,36 @@ namespace hud
55
{
66
struct character
77
{
8-
98
static constexpr char8 ANSI_NULL_CHARACTER = '\0';
109
static constexpr wchar WIDE_NULL_CHARACTER = L'\0';
10+
static constexpr char16 CHAR16_NULL_CHARACTER = u'\0';
11+
static constexpr char32 CHAR32_NULL_CHARACTER = U'\0';
1112

1213
/** Check whether the character is a pure ansi character. */
13-
static HD_FORCEINLINE constexpr bool is_ascii(const char8 character) noexcept
14-
{
15-
return (character & 0x80) == 0;
16-
}
17-
18-
/** Check whether the character is a pure ansi character. */
19-
static HD_FORCEINLINE constexpr bool is_ascii(const wchar character) noexcept
14+
template<typename char_t>
15+
requires(hud::is_one_of_types_v<char_t, char8, wchar, char16, char32>)
16+
static HD_FORCEINLINE constexpr bool is_ascii(const char_t character) noexcept
2017
{
2118
return (character & ~0x7F) == 0;
2219
}
2320

2421
/** Check whether the character is a null character '\0'. */
25-
static HD_FORCEINLINE constexpr bool is_null(const char8 character) noexcept
26-
{
27-
return character == '\0';
28-
}
29-
30-
/** Check whether the character is a null character '\0'. */
31-
static HD_FORCEINLINE constexpr bool is_null(const wchar character) noexcept
32-
{
33-
return character == L'\0';
22+
template<typename char_t>
23+
requires hud::is_one_of_types_v<char_t, char8, wchar, char16, char32>
24+
static HD_FORCEINLINE constexpr bool is_null(const char_t character) noexcept
25+
{
26+
if constexpr (std::is_same_v<char_t, char8>) {
27+
return character == ANSI_NULL_CHARACTER;
28+
}
29+
else if constexpr (std::is_same_v<char_t, wchar>) {
30+
return character == WIDE_NULL_CHARACTER;
31+
}
32+
else if constexpr (std::is_same_v<char_t, char16>) {
33+
return character == CHAR16_NULL_CHARACTER;
34+
}
35+
else if constexpr (std::is_same_v<char_t, char32>) {
36+
return character == CHAR32_NULL_CHARACTER;
37+
}
3438
}
3539

3640
/**

0 commit comments

Comments
 (0)