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
17
18
19namespace hi { inline namespace v1 {
20
25template<>
26struct char_map<"iso-8859-1"> {
27 using char_type = char;
28
29 [[nodiscard]] constexpr std::endian guess_endian(void const *ptr, size_t size, std::endian endian) const noexcept
30 {
31 return std::endian::native;
32 }
33
34 template<typename It, typename EndIt>
35 [[nodiscard]] constexpr std::pair<char32_t, bool> read(It& it, EndIt last) const noexcept
36 {
37 hi_axiom(it != last);
38 return {char_cast<char32_t>(*it++), true};
39 }
40
41 [[nodiscard]] constexpr std::pair<uint8_t, bool> size(char32_t code_point) const noexcept
42 {
43 hi_axiom(code_point < 0x11'0000);
44 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
45
46 if (code_point < 0x0100) {
47 return {uint8_t{1}, true};
48
49 } else {
50 return {uint8_t{1}, false};
51 }
52 }
53
54 template<typename It>
55 constexpr void write(char32_t code_point, It& dst) const noexcept
56 {
57 hi_axiom(code_point < 0x11'0000);
58 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
59
60 if (code_point < 0x0100) {
61 *dst++ = char_cast<char>(code_point);
62 } else {
63 *dst++ = '?';
64 }
65 }
66
67#if defined(HI_HAS_SSE2)
68 template<typename It>
69 hi_force_inline __m128i read_ascii_chunk16(It it) const noexcept
70 {
71 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(std::addressof(*it)));
72 }
73
74 template<typename It>
75 hi_force_inline void write_ascii_chunk16(__m128i chunk, It dst) const noexcept
76 {
77 _mm_storeu_si128(reinterpret_cast<__m128i *>(std::addressof(*dst)), chunk);
78 }
79#endif
80};
81
82}} // 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.
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Character encoder/decoder template.
Definition char_converter.hpp:86
T addressof(T... args)