HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_8859_1.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
9#pragma once
10
11#include "char_converter.hpp"
12#include "../utility/utility.hpp"
13#include "../macros.hpp"
14#include <cstdint>
15#include <utility>
16#include <bit>
17#include <compare>
18#if defined(HI_HAS_SSE2)
19#include <emmintrin.h>
20#endif
21
22hi_export_module(hikogui.char_maps.iso_8859_1);
23
24hi_export namespace hi { inline namespace v1 {
25
30template<>
31struct char_map<"iso-8859-1"> {
32 using char_type = char;
33
34 [[nodiscard]] constexpr std::endian guess_endian(void const *ptr, size_t size, std::endian endian) const noexcept
35 {
36 return std::endian::native;
37 }
38
39 template<typename It, typename EndIt>
40 [[nodiscard]] constexpr std::pair<char32_t, bool> read(It& it, EndIt last) const noexcept
41 {
42 hi_axiom(it != last);
43 return {char_cast<char32_t>(*it++), true};
44 }
45
46 [[nodiscard]] constexpr std::pair<uint8_t, bool> size(char32_t code_point) const noexcept
47 {
48 hi_axiom(code_point < 0x11'0000);
49 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
50
51 if (code_point < 0x0100) {
52 return {uint8_t{1}, true};
53
54 } else {
55 return {uint8_t{1}, false};
56 }
57 }
58
59 template<typename It>
60 constexpr void write(char32_t code_point, It& dst) const noexcept
61 {
62 hi_axiom(code_point < 0x11'0000);
63 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
64
65 if (code_point < 0x0100) {
66 *dst++ = char_cast<char>(code_point);
67 } else {
68 *dst++ = '?';
69 }
70 }
71
72#if defined(HI_HAS_SSE2)
73 template<typename It>
74 hi_force_inline __m128i read_ascii_chunk16(It it) const noexcept
75 {
76 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(std::addressof(*it)));
77 }
78
79 template<typename It>
80 hi_force_inline void write_ascii_chunk16(__m128i chunk, It dst) const noexcept
81 {
82 _mm_storeu_si128(reinterpret_cast<__m128i *>(std::addressof(*dst)), chunk);
83 }
84#endif
85};
86
87}} // namespace hi::v1
Definition of the char_converter<From,To> functor.
@ read
Allow read access to a file.
@ write
Allow write access to a file.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Character encoder/decoder template.
Definition char_converter.hpp:89
T addressof(T... args)