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 "../cast.hpp"
13#include "../utility.hpp"
14#include "../architecture.hpp"
15#include <cstdint>
16#include <utility>
17#include <tuple>
18
19namespace hi { inline namespace v1 {
20
24template<>
25struct char_map<"ascii"> {
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
38 hilet c = char_cast<char32_t>(*it++);
39 if (c < 0x80) {
40 return {c, true};
41 } else {
42 return {0xfffd, false};
43 }
44 }
45
46 [[nodiscard]] constexpr std::pair<uint8_t, bool> size(char32_t code_point) 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 < 0x80) {
52 return {uint8_t{1}, true};
53
54 } else {
55 return {uint8_t{1}, false};
56 }
57 }
58
59 template<typename It>
60 constexpr void write(char32_t code_point, It& dst) const noexcept
61 {
62 hi_axiom(code_point < 0x11'0000);
63 hi_axiom(not(code_point >= 0xd800 and code_point < 0xe000));
64
65 if (code_point < 0x80) {
66 *dst++ = char_cast<char>(code_point);
67
68 } else {
69 *dst++ = '?';
70 }
71 }
72
73#if defined(HI_HAS_SSE2)
74 template<typename It>
75 hi_force_inline __m128i read_ascii_chunk16(It it) const noexcept
76 {
77 return _mm_loadu_si128(reinterpret_cast<__m128i const *>(std::addressof(*it)));
78 }
79
80 template<typename It>
81 hi_force_inline void write_ascii_chunk16(__m128i chunk, It dst) const noexcept
82 {
83 _mm_storeu_si128(reinterpret_cast<__m128i *>(std::addressof(*dst)), chunk);
84 }
85#endif
86};
87
88}} // namespace hi::v1
Utilities used by the HikoGUI library itself.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
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
The HikoGUI namespace.
Definition ascii.hpp:19
Character encoder/decoder template.
Definition char_converter.hpp:85
T addressof(T... args)