1#ifndef SIMDUTF_UTF32_TO_LATIN1_H
2#define SIMDUTF_UTF32_TO_LATIN1_H
9namespace utf32_to_latin1 {
11inline simdutf_constexpr23
size_t convert(
const char32_t *data,
size_t len,
12 char *latin1_output) {
13 char *start = latin1_output;
16 uint32_t too_large = 0;
19 utf32_char = (uint32_t)data[pos];
20 too_large |= utf32_char;
21 *latin1_output++ = (char)(utf32_char & 0xFF);
24 if ((too_large & 0xFFFFFF00) != 0) {
27 return latin1_output - start;
30inline simdutf_constexpr23 result convert_with_errors(
const char32_t *data,
32 char *latin1_output) {
33 char *start{latin1_output};
36#if SIMDUTF_CPLUSPLUS23
43 ::memcpy(&v, data + pos,
sizeof(uint64_t));
44 if ((v & 0xFFFFFF00FFFFFF00) == 0) {
45 *latin1_output++ = char(data[pos]);
46 *latin1_output++ = char(data[pos + 1]);
53 uint32_t utf32_char = data[pos];
54 if ((utf32_char & 0xFFFFFF00) ==
56 *latin1_output++ = (char)(utf32_char & 0xFF);
59 return result(error_code::TOO_LARGE, pos);
62 return result(error_code::SUCCESS, latin1_output - start);
helpers placed in namespace detail are not a part of the public API