77
88namespace hud
99{
10- template <typename char_t , usize char_size = sizeof (char_t )>
11- struct utf16_string_view ;
12-
1310 template <typename char_t >
14- struct utf16_string_view < char_t , 2 >
11+ struct utf16_string_view
1512 {
1613
1714 /* * Type of the underlying character. */
1815 using char_type = char_t ;
1916
17+ /* * UTF16 string view only support 2 byte char_type. */
18+ static_assert (sizeof (char_t ) == 2 , " utf16_string_view requires char_t with sizeof(char_t) == 2 (UTF-16)" );
2019 /* *
2120 * Returns the length of the string (number of characters before the null terminator).
2221 * @return The length of the string in characters.
@@ -53,7 +52,7 @@ namespace hud
5352 * @return true if both strings are identical, false otherwise.
5453 */
5554 [[nodiscard]]
56- constexpr bool equals (const utf16_string_view<char_type, 1 > &v) const noexcept
55+ constexpr bool equals (const utf16_string_view<char_type> &v) const noexcept
5756 {
5857 return hud::cstring::equals (ptr_, v.ptr_ );
5958 }
@@ -65,7 +64,7 @@ namespace hud
6564 * @return true if the first n characters match, false otherwise.
6665 */
6766 [[nodiscard]]
68- constexpr bool equals_partial (const utf16_string_view<char_type, 1 > &v, const usize n) const noexcept
67+ constexpr bool equals_partial (const utf16_string_view<char_type> &v, const usize n) const noexcept
6968 {
7069 return hud::cstring::equals_partial (ptr_, v.ptr_ , n);
7170 }
@@ -88,7 +87,7 @@ namespace hud
8887 * @return Index of the first occurrence, or -1 if not found.
8988 */
9089 [[nodiscard]]
91- constexpr isize find_first (const utf16_string_view<char_type, 1 > &to_find) const noexcept
90+ constexpr isize find_first (const utf16_string_view<char_type> &to_find) const noexcept
9291 {
9392 return find_first (to_find.data ());
9493 }
@@ -122,7 +121,7 @@ namespace hud
122121 * @return true if the substring is found, false otherwise.
123122 */
124123 [[nodiscard]]
125- constexpr bool contains (const utf16_string_view<char_type, 1 > &to_find) const noexcept
124+ constexpr bool contains (const utf16_string_view<char_type> &to_find) const noexcept
126125 {
127126 return contains (to_find.data ());
128127 }
0 commit comments