11#include "../utility/utility.hpp"
12#include "../macros.hpp"
18#if defined(HI_HAS_SSE2)
22hi_export_module(hikogui.char_maps.char_converter);
24hi_export
namespace hi {
inline namespace v1 {
88template<fixed_
string Encoding>
97template<fixed_
string From, fixed_
string To>
102 using from_char_type = from_encoder_type::char_type;
103 using to_char_type = to_encoder_type::char_type;
113 template<
typename OutRange,
typename InRange>
121 auto const[size, valid] = _size(cbegin(
src), cend(
src));
124 if constexpr (
From ==
To and std::is_same_v<InRange, OutRange>) {
126 r = std::forward<InRange>(
src);
155 template<
typename OutRange,
typename It,
typename EndIt>
160 auto const[size, valid] = _size(first, last);
172 _convert(first, last,
begin(r));
185 template<
typename OutRange = std::basic_
string<to_
char_type>>
188 hi_assert_not_null(ptr);
190 auto const num_chars = size /
sizeof(from_char_type);
193 if (endian == std::endian::native) {
194 if (floor(ptr,
sizeof(from_char_type)) == ptr) {
196 reinterpret_cast<from_char_type
const *
>(ptr),
reinterpret_cast<from_char_type
const *
>(ptr) +
num_chars);
207 for (
auto& c :
tmp) {
208 c = std::byteswap(c);
219 template<
typename InRange>
226#if defined(HI_HAS_SSE2)
229 using chunk16_type =
void;
232 constexpr static bool _has_read_ascii_chunk16 =
true;
233 constexpr static bool _has_write_ascii_chunk16 =
true;
235 template<
typename It,
typename EndIt>
236 constexpr void _size_ascii(
It&
it,
EndIt last,
size_t& count)
const noexcept
238 if (
not std::is_constant_evaluated()) {
239#if defined(HI_HAS_SSE2)
240 if constexpr (_has_read_ascii_chunk16
and _has_write_ascii_chunk16) {
242 auto const chunk = from_encoder_type{}.read_ascii_chunk16(
it);
259 template<
typename SrcIt,
typename SrcEndIt,
typename DstIt>
262 if (
not std::is_constant_evaluated()) {
263#if defined(HI_HAS_SSE2)
264 if constexpr (_has_read_ascii_chunk16
and _has_write_ascii_chunk16) {
266 auto const chunk = from_encoder_type{}.read_ascii_chunk16(
src);
273 to_encoder_type{}.write_ascii_chunk16(
chunk,
dst);
282 template<
typename It,
typename EndIt>
290 _size_ascii(
it, last, count);
296 auto const[code_point,
read_valid] = from_encoder_type{}.read(
it, last);
304 return {
count, valid};
307 template<
typename SrcIt,
typename SrcEndIt,
typename DstIt>
320 to_encoder_type{}.write(code_point,
dst);
@ begin
Start from the beginning of the file.
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
Character encoder/decoder template.
Definition char_converter.hpp:89
A converter between character encodings.
Definition char_converter.hpp:98
constexpr to_string_type operator()(InRange &&src) const noexcept
Convert text between the given encodings.
Definition char_converter.hpp:220
constexpr OutRange convert(InRange &&src) const noexcept
Convert text between the given encodings.
Definition char_converter.hpp:114
constexpr OutRange convert(It first, EndIt last) const noexcept
Convert text between the given encodings.
Definition char_converter.hpp:156
OutRange read(void const *ptr, size_t size, std::endian endian=std::endian::native) noexcept
Read text from a byte array.
Definition char_converter.hpp:186