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/utility.hpp"
13#include "../macros.hpp"
14#include <cstdint>
15#include <utility>
16#include <tuple>
17
18
19
20namespace hi { inline namespace v1 {
21
25template<>
26struct char_map<"ascii"> {
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
39 hilet c = char_cast<char32_t>(*it++);
40 if (c < 0x80) {
41 return {c, true};
42 } else {
43 return {0xfffd, false};
44 }
45 }
46
47 [[nodiscard]] constexpr std::pair<uint8_t, bool> size(char32_t code_point) const noexcept
48 {
49 hi_axiom(code_point < 0x11'0000);
50 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
51
52 if (code_point < 0x80) {
53 return {uint8_t{1}, true};
54
55 } else {
56 return {uint8_t{1}, false};
57 }
58 }
59
60 template<typename It>
61 constexpr void write(char32_t code_point, It& dst) const noexcept
62 {
63 hi_axiom(code_point < 0x11'0000);
64 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
65
66 if (code_point < 0x80) {
67 *dst++ = char_cast<char>(code_point);
68
69 } else {
70 *dst++ = '?';
71 }
72 }
73
74#if defined(HI_HAS_SSE2)
75 template<typename It>
76 hi_force_inline __m128i read_ascii_chunk16(It it) const noexcept
77 {
78 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(std::addressof(*it)));
79 }
80
81 template<typename It>
82 hi_force_inline void write_ascii_chunk16(__m128i chunk, It dst) const noexcept
83 {
84 _mm_storeu_si128(reinterpret_cast<__m128i *>(std::addressof(*dst)), chunk);
85 }
86#endif
87};
88
89}} // 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)