1#ifndef SIMDUTF_VALID_UTF32_TO_UTF8_H
2#define SIMDUTF_VALID_UTF32_TO_UTF8_H
9namespace utf32_to_utf8 {
11template <
typename InputPtr,
typename OutputPtr>
12#if SIMDUTF_CPLUSPLUS20
13 requires(simdutf::detail::indexes_into_utf32<InputPtr> &&
14 simdutf::detail::index_assignable_from_char<OutputPtr>)
16simdutf_constexpr23
size_t convert_valid(InputPtr data,
size_t len,
17 OutputPtr utf8_output) {
19 auto start = utf8_output;
21#if SIMDUTF_CPLUSPLUS23
28 ::memcpy(&v, data + pos,
sizeof(uint64_t));
29 if ((v & 0xFFFFFF80FFFFFF80) == 0) {
30 *utf8_output++ = char(data[pos]);
31 *utf8_output++ = char(data[pos + 1]);
38 uint32_t word = data[pos];
39 if ((word & 0xFFFFFF80) == 0) {
41 *utf8_output++ = char(word);
43 }
else if ((word & 0xFFFFF800) == 0) {
46 *utf8_output++ = char((word >> 6) | 0b11000000);
47 *utf8_output++ = char((word & 0b111111) | 0b10000000);
49 }
else if ((word & 0xFFFF0000) == 0) {
52 *utf8_output++ = char((word >> 12) | 0b11100000);
53 *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
54 *utf8_output++ = char((word & 0b111111) | 0b10000000);
59 *utf8_output++ = char((word >> 18) | 0b11110000);
60 *utf8_output++ = char(((word >> 12) & 0b111111) | 0b10000000);
61 *utf8_output++ = char(((word >> 6) & 0b111111) | 0b10000000);
62 *utf8_output++ = char((word & 0b111111) | 0b10000000);
66 return utf8_output - start;
helpers placed in namespace detail are not a part of the public API