Debian Codegraph @

core/string/char_utils.h

raw symbols SCIP
1 /**************************************************************************/
2 /* char_utils.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/typedefs.h"
34
35 #include "char_range.inc"
36
37 static constexpr char hex_char_table_upper[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
38 static constexpr char hex_char_table_lower[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
39
40 #define BSEARCH_CHAR_RANGE(m_array) \
41 int low = 0; \
42 int high = std_size(m_array) - 1; \
43 int middle = (low + high) / 2; \
44 \
45 while (low <= high) { \
46 if (p_char < m_array[middle].start) { \
47 high = middle - 1; \
48 } else if (p_char > m_array[middle].end) { \
49 low = middle + 1; \
50 } else { \
51 return true; \
52 } \
53 \
54 middle = (low + high) / 2; \
55 } \
56 \
57 return false
58
59 constexpr bool is_unicode_identifier_start(char32_t p_char) {
60 BSEARCH_CHAR_RANGE(xid_start);
61 }
62
63 constexpr bool is_unicode_identifier_continue(char32_t p_char) {
64 BSEARCH_CHAR_RANGE(xid_continue);
65 }
66
67 constexpr bool is_unicode_upper_case(char32_t p_char) {
68 BSEARCH_CHAR_RANGE(uppercase_letter);
69 }
70
71 constexpr bool is_unicode_lower_case(char32_t p_char) {
72 BSEARCH_CHAR_RANGE(lowercase_letter);
73 }
74
75 constexpr bool is_unicode_letter(char32_t p_char) {
76 BSEARCH_CHAR_RANGE(unicode_letter);
77 }
78
79 #undef BSEARCH_CHAR_RANGE
80
81 constexpr bool is_ascii_upper_case(char32_t p_char) {
82 return (p_char >= 'A' && p_char <= 'Z');
83 }
84
85 constexpr bool is_ascii_lower_case(char32_t p_char) {
86 return (p_char >= 'a' && p_char <= 'z');
87 }
88
89 constexpr bool is_digit(char32_t p_char) {
90 return (p_char >= '0' && p_char <= '9');
91 }
92
93 constexpr bool is_hex_digit(char32_t p_char) {
94 return (is_digit(p_char) || (p_char >= 'a' && p_char <= 'f') || (p_char >= 'A' && p_char <= 'F'));
95 }
96
97 constexpr bool is_binary_digit(char32_t p_char) {
98 return (p_char == '0' || p_char == '1');
99 }
100
101 constexpr bool is_ascii_alphabet_char(char32_t p_char) {
102 return (p_char >= 'a' && p_char <= 'z') || (p_char >= 'A' && p_char <= 'Z');
103 }
104
105 constexpr bool is_ascii_alphanumeric_char(char32_t p_char) {
106 return (p_char >= 'a' && p_char <= 'z') || (p_char >= 'A' && p_char <= 'Z') || (p_char >= '0' && p_char <= '9');
107 }
108
109 constexpr bool is_ascii_identifier_char(char32_t p_char) {
110 return (p_char >= 'a' && p_char <= 'z') || (p_char >= 'A' && p_char <= 'Z') || (p_char >= '0' && p_char <= '9') || p_char == '_';
111 }
112
113 constexpr bool is_symbol(char32_t p_char) {
114 return p_char != '_' && ((p_char >= '!' && p_char <= '/') || (p_char >= ':' && p_char <= '@') || (p_char >= '[' && p_char <= '`') || (p_char >= '{' && p_char <= '~') || p_char == '\t' || p_char == ' ');
115 }
116
117 constexpr bool is_control(char32_t p_char) {
118 return (p_char <= 0x001f) || (p_char >= 0x007f && p_char <= 0x009f);
119 }
120
121 constexpr bool is_whitespace(char32_t p_char) {
122 return (p_char == ' ') || (p_char == 0x00a0) || (p_char == 0x1680) || (p_char >= 0x2000 && p_char <= 0x200b) || (p_char == 0x202f) || (p_char == 0x205f) || (p_char == 0x3000) || (p_char == 0x2028) || (p_char == 0x2029) || (p_char >= 0x0009 && p_char <= 0x000d) || (p_char == 0x0085);
123 }
124
125 constexpr bool is_linebreak(char32_t p_char) {
126 return (p_char >= 0x000a && p_char <= 0x000d) || (p_char == 0x0085) || (p_char == 0x2028) || (p_char == 0x2029);
127 }
128
129 constexpr bool is_punct(char32_t p_char) {
130 return (p_char >= ' ' && p_char <= '/') || (p_char >= ':' && p_char <= '@') || (p_char >= '[' && p_char <= '^') || (p_char == '`') || (p_char >= '{' && p_char <= '~') || (p_char >= 0x2000 && p_char <= 0x206f) || (p_char >= 0x3000 && p_char <= 0x303f);
131 }
132
133 constexpr bool is_underscore(char32_t p_char) {
134 return (p_char == '_');
135 }
136
137 constexpr bool is_hyphen(char32_t p_char) {
138 return (p_char == '-') || (p_char == 0x2010) || (p_char == 0x2011);
139 }