HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_8859_1.hpp
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
5#pragma once
6
7#include "char_converter.hpp"
8#include "../cast.hpp"
9#include "../required.hpp"
10#include "../architecture.hpp"
11#include <cstdint>
12#include <utility>
13
14namespace hi::inline v1 {
15
16template<>
17struct char_map<"iso-8859-1"> {
18 using char_type = char;
19
20 [[nodiscard]] constexpr std::endian guess_endian(void const *ptr, size_t size, std::endian endian) const noexcept
21 {
22 return std::endian::native;
23 }
24
25 template<typename It, typename EndIt>
26 [[nodiscard]] constexpr std::pair<char32_t, bool> read(It &it, EndIt last) const noexcept
27 {
28 hi_axiom(it != last);
29 return {char_cast<char32_t>(*it++), true};
30 }
31
32 [[nodiscard]] constexpr std::pair<uint8_t, bool> size(char32_t code_point) const noexcept
33 {
34 hi_axiom(code_point < 0x11'0000);
35 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
36
37 if (code_point < 0x0100) {
38 return {uint8_t{1}, true};
39
40 } else {
41 return {uint8_t{1}, false};
42 }
43 }
44
45 template<typename It>
46 constexpr void write(char32_t code_point, It& dst) 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 *dst++ = char_cast<char>(code_point);
53 } else {
54 *dst++ = '?';
55 }
56 }
57
58#if defined(HI_HAS_SSE2)
59 template<typename It>
60 hi_force_inline __m128i read_ascii_chunk16(It it) const noexcept
61 {
62 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(std::addressof(*it)));
63 }
64
65 template<typename It>
66 hi_force_inline void write_ascii_chunk16(__m128i chunk, It dst) const noexcept
67 {
68 _mm_storeu_si128(reinterpret_cast<__m128i *>(std::addressof(*dst)), chunk);
69 }
70#endif
71};
72
73} // namespace hi::inline v1
This file includes required definitions.
Functions and macros for handling architectural difference between compilers, CPUs and operating syst...
Character encoder/decoder template.
Definition char_converter.hpp:34
T addressof(T... args)