1#ifndef SIMDUTF_UTF32_TO_LATIN1_H
2#define SIMDUTF_UTF32_TO_LATIN1_H
7namespace utf32_to_latin1 {
9inline simdutf_constexpr23
size_t convert(
const char32_t *data,
size_t len,
10 char *latin1_output) {
11 char *start = latin1_output;
14 uint32_t too_large = 0;
17 utf32_char = (uint32_t)data[pos];
18 too_large |= utf32_char;
19 *latin1_output++ = (char)(utf32_char & 0xFF);
22 if ((too_large & 0xFFFFFF00) != 0) {
25 return latin1_output - start;
28inline simdutf_constexpr23 result convert_with_errors(
const char32_t *data,
30 char *latin1_output) {
31 char *start{latin1_output};
34#if SIMDUTF_CPLUSPLUS23
41 ::memcpy(&v, data + pos,
sizeof(uint64_t));
42 if ((v & 0xFFFFFF00FFFFFF00) == 0) {
43 *latin1_output++ = char(data[pos]);
44 *latin1_output++ = char(data[pos + 1]);
51 uint32_t utf32_char = data[pos];
52 if ((utf32_char & 0xFFFFFF00) ==
54 *latin1_output++ = (char)(utf32_char & 0xFF);
57 return result(error_code::TOO_LARGE, pos);
60 return result(error_code::SUCCESS, latin1_output - start);