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 "../cast.hpp"
13#include "../utility.hpp"
14#include "../architecture.hpp"
15#include <cstdint>
16#include <utility>
17
18namespace hi { inline namespace v1 {
19
24template<>
25struct char_map<"iso-8859-1"> {
26 using char_type = char;
27
28 [[nodiscard]] constexpr std::endian guess_endian(void const *ptr, size_t size, std::endian endian) const noexcept
29 {
30 return std::endian::native;
31 }
32
33 template<typename It, typename EndIt>
34 [[nodiscard]] constexpr std::pair<char32_t, bool> read(It& it, EndIt last) const noexcept
35 {
36 hi_axiom(it != last);
37 return {char_cast<char32_t>(*it++), true};
38 }
39
40 [[nodiscard]] constexpr std::pair<uint8_t, bool> size(char32_t code_point) const noexcept
41 {
42 hi_axiom(code_point < 0x11'0000);
43 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
44
45 if (code_point < 0x0100) {
46 return {uint8_t{1}, true};
47
48 } else {
49 return {uint8_t{1}, false};
50 }
51 }
52
53 template<typename It>
54 constexpr void write(char32_t code_point, It& dst) const noexcept
55 {
56 hi_axiom(code_point < 0x11'0000);
57 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
58
59 if (code_point < 0x0100) {
60 *dst++ = char_cast<char>(code_point);
61 } else {
62 *dst++ = '?';
63 }
64 }
65
66#if defined(HI_HAS_SSE2)
67 template<typename It>
68 hi_force_inline __m128i read_ascii_chunk16(It it) const noexcept
69 {
70 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(std::addressof(*it)));
71 }
72
73 template<typename It>
74 hi_force_inline void write_ascii_chunk16(__m128i chunk, It dst) const noexcept
75 {
76 _mm_storeu_si128(reinterpret_cast<__m128i *>(std::addressof(*dst)), chunk);
77 }
78#endif
79};
80
81}} // namespace hi::v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
Utilities used by the HikoGUI library itself.
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
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:15
geometry/margins.hpp
Definition assert.hpp:18
Character encoder/decoder template.
Definition char_converter.hpp:85
T addressof(T... args)