HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
ascii.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#include <tuple>
16
17namespace hi { inline namespace v1 {
18
22template<>
23struct char_map<"ascii"> {
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
36 hilet c = char_cast<char32_t>(*it++);
37 if (c < 0x80) {
38 return {c, true};
39 } else {
40 return {0xfffd, false};
41 }
42 }
43
44 [[nodiscard]] constexpr std::pair<uint8_t, bool> size(char32_t code_point) const noexcept
45 {
46 hi_axiom(code_point < 0x11'0000);
47 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
48
49 if (code_point < 0x80) {
50 return {uint8_t{1}, true};
51
52 } else {
53 return {uint8_t{1}, false};
54 }
55 }
56
57 template<typename It>
58 constexpr void write(char32_t code_point, It& dst) const noexcept
59 {
60 hi_axiom(code_point < 0x11'0000);
61 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
62
63 if (code_point < 0x80) {
64 *dst++ = char_cast<char>(code_point);
65
66 } else {
67 *dst++ = '?';
68 }
69 }
70
71#if defined(HI_HAS_SSE2)
72 template<typename It>
73 hi_force_inline __m128i read_ascii_chunk16(It it) const noexcept
74 {
75 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(std::addressof(*it)));
76 }
77
78 template<typename It>
79 hi_force_inline void write_ascii_chunk16(__m128i chunk, It dst) const noexcept
80 {
81 _mm_storeu_si128(reinterpret_cast<__m128i *>(std::addressof(*dst)), chunk);
82 }
83#endif
84};
85
86}} // 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
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ 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)