1#ifndef SIMDUTF_VALID_UTF8_TO_LATIN1_H
2#define SIMDUTF_VALID_UTF8_TO_LATIN1_H
9namespace utf8_to_latin1 {
11template <
typename InputPtr>
12#if SIMDUTF_CPLUSPLUS20
13 requires simdutf::detail::indexes_into_byte_like<InputPtr>
15simdutf_constexpr23
size_t convert_valid(InputPtr data,
size_t len,
19 char *start{latin_output};
22#if SIMDUTF_CPLUSPLUS23
27 if (pos + 16 <= len) {
30 ::memcpy(&v1, data + pos,
sizeof(uint64_t));
32 ::memcpy(&v2, data + pos +
sizeof(uint64_t),
sizeof(uint64_t));
36 if ((v & 0x8080808080808080) ==
39 size_t final_pos = pos + 16;
40 while (pos < final_pos) {
41 *latin_output++ = uint8_t(data[pos]);
50 auto leading_byte = uint8_t(data[pos]);
51 if (leading_byte < 0b10000000) {
53 *latin_output++ = char(leading_byte);
55 }
else if ((leading_byte & 0b11100000) ==
61 if ((uint8_t(data[pos + 1]) & 0b11000000) != 0b10000000) {
67 (leading_byte & 0b00011111) << 6 |
68 (uint8_t(data[pos + 1]) &
74 *latin_output++ = char(code_point);
81 return latin_output - start;
helpers placed in namespace detail are not a part of the public API