1#ifndef SIMDUTF_VALID_UTF32_TO_UTF16_H
2#define SIMDUTF_VALID_UTF32_TO_UTF16_H
7namespace utf32_to_utf16 {
9template <endianness big_endian>
10simdutf_constexpr23
size_t convert_valid(
const char32_t *data,
size_t len,
11 char16_t *utf16_output) {
13 char16_t *start{utf16_output};
15 uint32_t word = data[pos];
16 if ((word & 0xFFFF0000) == 0) {
18 *utf16_output++ = !match_system(big_endian)
19 ? char16_t(u16_swap_bytes(uint16_t(word)))
25 uint16_t high_surrogate = uint16_t(0xD800 + (word >> 10));
26 uint16_t low_surrogate = uint16_t(0xDC00 + (word & 0x3FF));
27 if simdutf_constexpr (!match_system(big_endian)) {
28 high_surrogate = u16_swap_bytes(high_surrogate);
29 low_surrogate = u16_swap_bytes(low_surrogate);
31 *utf16_output++ = char16_t(high_surrogate);
32 *utf16_output++ = char16_t(low_surrogate);
36 return utf16_output - start;