Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
unicode.hpp
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
7#include "header_start.hpp"
10
13 constexpr bool is_string_delimiter(char32_t c) noexcept {
14 return c == U'"' || c == U'\'';
15 }
16
18 constexpr bool is_ascii_letter(char32_t c) noexcept {
19 return (c >= U'a' && c <= U'z') || (c >= U'A' && c <= U'Z');
20 }
21
23 constexpr bool is_binary_digit(char32_t c) noexcept {
24 return c == U'0' || c == U'1';
25 }
26
28 constexpr bool is_octal_digit(char32_t c) noexcept {
29 return (c >= U'0' && c <= U'7');
30 }
31
33 constexpr bool is_decimal_digit(char32_t c) noexcept {
34 return (c >= U'0' && c <= U'9');
35 }
36
38 constexpr bool is_hexadecimal_digit(char32_t c) noexcept {
39 return U'0' <= c && c <= U'f' &&
40 (1ull << (static_cast<uint_least64_t>(c) - 0x30u)) & 0x7E0000007E03FFull;
41 }
42
43 template <typename T>
44 TOML_CONST_GETTER constexpr uint_least32_t hex_to_dec(const T c) noexcept {
45 if constexpr (std::is_same_v<remove_cvref<T>, uint_least32_t>)
46 return c >= 0x41u // >= 'A'
47 ? 10u + (c | 0x20u) - 0x61u // - 'a'
48 : c - 0x30u // - '0'
49 ;
50 else
51 return hex_to_dec(static_cast<uint_least32_t>(c));
52 }
53
55 constexpr bool is_horizontal_whitespace(char32_t c) noexcept {
56 return is_ascii_horizontal_whitespace(c) || is_non_ascii_horizontal_whitespace(c);
57 }
58
60 constexpr bool is_vertical_whitespace(char32_t c) noexcept {
61 return is_ascii_vertical_whitespace(c) || is_non_ascii_vertical_whitespace(c);
62 }
63
65 constexpr bool is_whitespace(char32_t c) noexcept {
66 return is_horizontal_whitespace(c) || is_vertical_whitespace(c);
67 }
68
70 constexpr bool is_bare_key_character(char32_t c) noexcept {
71 return is_ascii_bare_key_character(c)
72#if TOML_LANG_UNRELEASED // toml/pull/891 (unicode bare keys)
73 || is_non_ascii_bare_key_character(c)
74#endif
75 ;
76 }
77
79 constexpr bool is_value_terminator(char32_t c) noexcept {
80 return is_whitespace(c) || c == U']' || c == U'}' || c == U',' || c == U'#';
81 }
82
84 constexpr bool is_control_character(char c) noexcept {
85 return c <= '\u001F' || c == '\u007F';
86 }
87
89 constexpr bool is_control_character(char32_t c) noexcept {
90 return c <= U'\u001F' || c == U'\u007F';
91 }
92
94 constexpr bool is_nontab_control_character(char32_t c) noexcept {
95 return c <= U'\u0008' || (c >= U'\u000A' && c <= U'\u001F') || c == U'\u007F';
96 }
97
99 constexpr bool is_unicode_surrogate(char32_t c) noexcept {
100 return c >= 0xD800u && c <= 0xDFFF;
101 }
102
103 struct utf8_decoder {
104 // utf8_decoder based on this: https://bjoern.hoehrmann.de/utf-8/decoder/dfa/
105 // Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de>
106
107 uint_least32_t state{};
108 char32_t codepoint{};
109
110 static constexpr uint8_t state_table[]{
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
117 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
118 9, 9, 9, 9, 9, 9, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
119 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 2, 2, 2, 2,
120 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
121 2, 2, 2, 2, 10, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 11, 6,
122 6, 6, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
123
124 0, 12, 24, 36, 60, 96, 84, 12, 12, 12, 48, 72, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
125 12, 12, 12, 0, 12, 12, 12, 12, 12, 0, 12, 0, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24,
126 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12, 12, 24, 12, 12, 12, 12,
127 12, 12, 12, 24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12,
128 12, 12, 12, 36, 12, 36, 12, 12, 12, 36, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12};
129
131 constexpr bool error() const noexcept { return state == uint_least32_t{12u}; }
132
134 constexpr bool has_code_point() const noexcept { return state == uint_least32_t{}; }
135
137 constexpr bool needs_more_input() const noexcept { return !has_code_point() && !error(); }
138
139 constexpr void operator()(uint8_t byte) noexcept {
141
142 const auto type = state_table[byte];
143
144 codepoint = static_cast<char32_t>(has_code_point()
145 ? (uint_least32_t{255u} >> type) & byte
146 : (byte & uint_least32_t{63u}) |
147 (static_cast<uint_least32_t>(codepoint) << 6));
148
149 state = state_table[state + uint_least32_t{256u} + type];
150 }
151
153 constexpr void operator()(char c) noexcept { operator()(static_cast<uint8_t>(c)); }
154
156 constexpr void reset() noexcept { state = {}; }
157 };
158
160 TOML_ATTR(nonnull)
161 bool is_ascii(const char* str, size_t len) noexcept;
162}
164
166#include "header_end.hpp"
#define T
Definition 17.names.cpp:163
#define c
Definition 17.names.cpp:111
#define len
Definition 17.names.cpp:488
#define U
Definition 17.names.cpp:164
const char * str
Definition exec.cpp:170
#define TOML_ASSERT_ASSUME(expr)
@ error
throw a parse_error exception in case of a tag
#define TOML_CONST_GETTER
#define TOML_PURE_GETTER
#define TOML_ATTR(...)
#define TOML_PURE_INLINE_GETTER
#define TOML_ALWAYS_INLINE
#define TOML_IMPL_NAMESPACE_END
#define TOML_IMPL_NAMESPACE_START