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/module.hpp"
13#include <cstdint>
14#include <utility>
15
16namespace hi { inline namespace v1 {
17
22template<>
23struct char_map<"iso-8859-1"> {
24 using char_type = char;
25
26 [[nodiscard]] constexpr std::endian guess_endian(void const *ptr, size_t size, std::endian endian) const noexcept
27 {
28 return std::endian::native;
29 }
30
31 template<typename It, typename EndIt>
32 [[nodiscard]] constexpr std::pair<char32_t, bool> read(It& it, EndIt last) const noexcept
33 {
34 hi_axiom(it != last);
35 return {char_cast<char32_t>(*it++), true};
36 }
37
38 [[nodiscard]] constexpr std::pair<uint8_t, bool> size(char32_t code_point) const noexcept
39 {
40 hi_axiom(code_point < 0x11'0000);
41 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
42
43 if (code_point < 0x0100) {
44 return {uint8_t{1}, true};
45
46 } else {
47 return {uint8_t{1}, false};
48 }
49 }
50
51 template<typename It>
52 constexpr void write(char32_t code_point, It& dst) const noexcept
53 {
54 hi_axiom(code_point < 0x11'0000);
55 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
56
57 if (code_point < 0x0100) {
58 *dst++ = char_cast<char>(code_point);
59 } else {
60 *dst++ = '?';
61 }
62 }
63
64#if defined(HI_HAS_SSE2)
65 template<typename It>
66 hi_force_inline __m128i read_ascii_chunk16(It it) const noexcept
67 {
68 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(std::addressof(*it)));
69 }
70
71 template<typename It>
72 hi_force_inline void write_ascii_chunk16(__m128i chunk, It dst) const noexcept
73 {
74 _mm_storeu_si128(reinterpret_cast<__m128i *>(std::addressof(*dst)), chunk);
75 }
76#endif
77};
78
79}} // namespace hi::v1
Definition of the char_converter<From,To> functor.
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
@ read
Allow read access to a file.
@ write
Allow write access to a file.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Character encoder/decoder template.
Definition char_converter.hpp:83
T addressof(T... args)