MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / utf8_to_utf32

Function utf8_to_utf32

modules/core/core/include/OpenString/unicode.h:125–141  ·  view source on GitHub ↗

* @param utf8 input utf-8 code unit sequence * @param length length of utf-8 code unit sequence * @return codepoint of input utf8 code unit sequence */

Source from the content-addressed store, hash-verified

123 * @return codepoint of input utf8 code unit sequence
124 */
125 [[nodiscard]] constexpr char32_t utf8_to_utf32(ochar8_t const* const utf8, const u64 length) noexcept
126 {
127 if (!utf8)
128 return 0;
129 const ochar8_t c0 = utf8[0];
130 const ochar8_t lead_mask = get_utf8_mask(length);
131 char32_t utf32 = c0 & lead_mask;
132 constexpr ochar8_t following_mask = get_utf8_mask(0);
133 for (u64 i = 1; i < length; ++i)
134 {
135 constexpr u64 bits_following = 6;
136 const ochar8_t ci = utf8[i];
137 utf32 <<= bits_following;
138 utf32 |= ci & following_mask;
139 }
140 return utf32;
141 }
142
143 /**
144 * @param utf32 input utf-32 code unit

Callers 2

utf8_to_utf16Function · 0.85
get_codepointMethod · 0.85

Calls 1

get_utf8_maskFunction · 0.85

Tested by

no test coverage detected