Debian Codegraph @

src/util/pm_char.c

raw symbols SCIP
1 #cxx . . $ `<file>/src/util/pm_char.c`/include "prism/util/pm_char.h"cxx . . $ `<file>/include/prism/util/pm_char.h`/
2
3 #define PRISM_CHAR_BIT_WHITESPACEcxx . . $ `src/util/pm_char.c:3:9`! (1 << 0)
4 #define PRISM_CHAR_BIT_INLINE_WHITESPACEcxx . . $ `src/util/pm_char.c:4:9`! (1 << 1)
5 #define PRISM_CHAR_BIT_REGEXP_OPTIONcxx . . $ `src/util/pm_char.c:5:9`! (1 << 2)
6
7 #define PRISM_NUMBER_BIT_BINARY_DIGITcxx . . $ `src/util/pm_char.c:7:9`! (1 << 0)
8 #define PRISM_NUMBER_BIT_BINARY_NUMBERcxx . . $ `src/util/pm_char.c:8:9`! (1 << 1)
9 #define PRISM_NUMBER_BIT_OCTAL_DIGITcxx . . $ `src/util/pm_char.c:9:9`! (1 << 2)
10 #define PRISM_NUMBER_BIT_OCTAL_NUMBERcxx . . $ `src/util/pm_char.c:10:9`! (1 << 3)
11 #define PRISM_NUMBER_BIT_DECIMAL_DIGITcxx . . $ `src/util/pm_char.c:11:9`! (1 << 4)
12 #define PRISM_NUMBER_BIT_DECIMAL_NUMBERcxx . . $ `src/util/pm_char.c:12:9`! (1 << 5)
13 #define PRISM_NUMBER_BIT_HEXADECIMAL_DIGITcxx . . $ `src/util/pm_char.c:13:9`! (1 << 6)
14 #define PRISM_NUMBER_BIT_HEXADECIMAL_NUMBERcxx . . $ `src/util/pm_char.c:14:9`! (1 << 7)
15
16 static const uint8_tcxx . . $ uint8_t# pm_byte_tablecxx . . $ pm_byte_table.[256] = {
17 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
18 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 3, 3, 3, 0, 0, // 0x
19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
20 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 2x
21 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 3x
22 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 4x
23 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, // 5x
24 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // 6x
25 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, // 7x
26 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
27 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
28 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ax
29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Bx
30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Cx
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Dx
32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Ex
33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Fx
34 };
35
36 static const uint8_tcxx . . $ uint8_t# pm_number_tablecxx . . $ pm_number_table.[256] = {
37 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x
39 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 1x
40 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 2x
41 0xff, 0xff, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 3x
42 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 4x
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, // 5x
44 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 6x
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 7x
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 8x
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 9x
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ax
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Bx
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Cx
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Dx
52 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Ex
53 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Fx
54 };
55
56 /**
57 * Returns the number of characters at the start of the string that match the
58 * given kind. Disallows searching past the given maximum number of characters.
59 */
60 static inline size_t
61 pm_strspn_char_kindcxx . . $ pm_strspn_char_kind(9e2afee6ff424c3d).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length, uint8_tcxx . . $ uint8_t# kind) {
62 if (length <= 0) return 0;
63
64 size_t size = 0;
65 size_t maximum = (size_t) length;
66
67 while (size < maximum && (pm_byte_tablecxx . . $ pm_byte_table.[string[size]] & kind)) size++;
68 return size;
69 }
70
71 /**
72 * Returns the number of characters at the start of the string that are
73 * whitespace. Disallows searching past the given maximum number of characters.
74 */
75 size_t
76 pm_strspn_whitespacecxx . . $ pm_strspn_whitespace(dc9dc2cf7fc514b1).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length) {
77 return pm_strspn_char_kindcxx . . $ pm_strspn_char_kind(9e2afee6ff424c3d).(string, length, PRISM_CHAR_BIT_WHITESPACEcxx . . $ `src/util/pm_char.c:3:9`!);
78 }
79
80 /**
81 * Returns the number of characters at the start of the string that are
82 * whitespace while also tracking the location of each newline. Disallows
83 * searching past the given maximum number of characters.
84 */
85 size_t
86 pm_strspn_whitespace_newlinescxx . . $ pm_strspn_whitespace_newlines(37d9c29a1a11cc01).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length, pm_newline_list_tcxx . . $ pm_newline_list_t# *newline_list) {
87 if (length <= 0) return 0;
88
89 size_t size = 0;
90 size_t maximum = (size_t) length;
91
92 while (size < maximum && (pm_byte_tablecxx . . $ pm_byte_table.[string[size]] & PRISM_CHAR_BIT_WHITESPACEcxx . . $ `src/util/pm_char.c:3:9`!)) {
93 if (string[size] == '\n') {
94 pm_newline_list_appendcxx . . $ pm_newline_list_append(93623494a75c4b1f).(newline_list, string + size);
95 }
96
97 size++;
98 }
99
100 return size;
101 }
102
103 /**
104 * Returns the number of characters at the start of the string that are inline
105 * whitespace. Disallows searching past the given maximum number of characters.
106 */
107 size_t
108 pm_strspn_inline_whitespacecxx . . $ pm_strspn_inline_whitespace(dc9dc2cf7fc514b1).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length) {
109 return pm_strspn_char_kindcxx . . $ pm_strspn_char_kind(9e2afee6ff424c3d).(string, length, PRISM_CHAR_BIT_INLINE_WHITESPACEcxx . . $ `src/util/pm_char.c:4:9`!);
110 }
111
112 /**
113 * Returns the number of characters at the start of the string that are regexp
114 * options. Disallows searching past the given maximum number of characters.
115 */
116 size_t
117 pm_strspn_regexp_optioncxx . . $ pm_strspn_regexp_option(dc9dc2cf7fc514b1).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length) {
118 return pm_strspn_char_kindcxx . . $ pm_strspn_char_kind(9e2afee6ff424c3d).(string, length, PRISM_CHAR_BIT_REGEXP_OPTIONcxx . . $ `src/util/pm_char.c:5:9`!);
119 }
120
121 /**
122 * Returns true if the given character matches the given kind.
123 */
124 static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
125 pm_char_is_char_kindcxx . . $ pm_char_is_char_kind(4ed805b44025c28a).(const uint8_tcxx . . $ uint8_t# b, uint8_tcxx . . $ uint8_t# kind) {
126 return (pm_byte_tablecxx . . $ pm_byte_table.[b] & kind) != 0;
127 }
128
129 /**
130 * Returns true if the given character is a whitespace character.
131 */
132 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
133 pm_char_is_whitespacecxx . . $ pm_char_is_whitespace(cef82f9be00a201a).(const uint8_tcxx . . $ uint8_t# b) {
134 return pm_char_is_char_kindcxx . . $ pm_char_is_char_kind(4ed805b44025c28a).(b, PRISM_CHAR_BIT_WHITESPACEcxx . . $ `src/util/pm_char.c:3:9`!);
135 }
136
137 /**
138 * Returns true if the given character is an inline whitespace character.
139 */
140 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
141 pm_char_is_inline_whitespacecxx . . $ pm_char_is_inline_whitespace(cef82f9be00a201a).(const uint8_tcxx . . $ uint8_t# b) {
142 return pm_char_is_char_kindcxx . . $ pm_char_is_char_kind(4ed805b44025c28a).(b, PRISM_CHAR_BIT_INLINE_WHITESPACEcxx . . $ `src/util/pm_char.c:4:9`!);
143 }
144
145 /**
146 * Scan through the string and return the number of characters at the start of
147 * the string that match the given kind. Disallows searching past the given
148 * maximum number of characters.
149 */
150 static inline size_t
151 pm_strspn_number_kindcxx . . $ pm_strspn_number_kind(9e2afee6ff424c3d).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length, uint8_tcxx . . $ uint8_t# kind) {
152 if (length <= 0) return 0;
153
154 size_t size = 0;
155 size_t maximum = (size_t) length;
156
157 while (size < maximum && (pm_number_tablecxx . . $ pm_number_table.[string[size]] & kind)) size++;
158 return size;
159 }
160
161 /**
162 * Scan through the string and return the number of characters at the start of
163 * the string that match the given kind. Disallows searching past the given
164 * maximum number of characters.
165 *
166 * Additionally, report the location of the last invalid underscore character
167 * found in the string through the out invalid parameter.
168 */
169 static inline size_t
170 pm_strspn_number_kind_underscorescxx . . $ pm_strspn_number_kind_underscores(86457d1d07599b5c).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length, const uint8_tcxx . . $ uint8_t# **invalid, uint8_tcxx . . $ uint8_t# kind) {
171 if (length <= 0) return 0;
172
173 size_t size = 0;
174 size_t maximum = (size_t) length;
175
176 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! underscore = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
177 while (size < maximum && (pm_number_tablecxx . . $ pm_number_table.[string[size]] & kind)) {
178 if (string[size] == '_') {
179 if (underscore) *invalid = string + size;
180 underscore = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
181 } else {
182 underscore = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
183 }
184
185 size++;
186 }
187
188 if (size > 0 && string[size - 1] == '_') *invalid = string + size - 1;
189 return size;
190 }
191
192 /**
193 * Returns the number of characters at the start of the string that are binary
194 * digits or underscores. Disallows searching past the given maximum number of
195 * characters.
196 *
197 * If multiple underscores are found in a row or if an underscore is
198 * found at the end of the number, then the invalid pointer is set to the index
199 * of the first invalid underscore.
200 */
201 size_t
202 pm_strspn_binary_numbercxx . . $ pm_strspn_binary_number(2f92041e72109b76).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length, const uint8_tcxx . . $ uint8_t# **invalid) {
203 return pm_strspn_number_kind_underscorescxx . . $ pm_strspn_number_kind_underscores(86457d1d07599b5c).(string, length, invalid, PRISM_NUMBER_BIT_BINARY_NUMBERcxx . . $ `src/util/pm_char.c:8:9`!);
204 }
205
206 /**
207 * Returns the number of characters at the start of the string that are octal
208 * digits or underscores. Disallows searching past the given maximum number of
209 * characters.
210 *
211 * If multiple underscores are found in a row or if an underscore is
212 * found at the end of the number, then the invalid pointer is set to the index
213 * of the first invalid underscore.
214 */
215 size_t
216 pm_strspn_octal_numbercxx . . $ pm_strspn_octal_number(2f92041e72109b76).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length, const uint8_tcxx . . $ uint8_t# **invalid) {
217 return pm_strspn_number_kind_underscorescxx . . $ pm_strspn_number_kind_underscores(86457d1d07599b5c).(string, length, invalid, PRISM_NUMBER_BIT_OCTAL_NUMBERcxx . . $ `src/util/pm_char.c:10:9`!);
218 }
219
220 /**
221 * Returns the number of characters at the start of the string that are decimal
222 * digits. Disallows searching past the given maximum number of characters.
223 */
224 size_t
225 pm_strspn_decimal_digitcxx . . $ pm_strspn_decimal_digit(dc9dc2cf7fc514b1).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length) {
226 return pm_strspn_number_kindcxx . . $ pm_strspn_number_kind(9e2afee6ff424c3d).(string, length, PRISM_NUMBER_BIT_DECIMAL_DIGITcxx . . $ `src/util/pm_char.c:11:9`!);
227 }
228
229 /**
230 * Returns the number of characters at the start of the string that are decimal
231 * digits or underscores. Disallows searching past the given maximum number of
232 * characters.
233 *
234 * If multiple underscores are found in a row or if an underscore is
235 * found at the end of the number, then the invalid pointer is set to the index
236 * of the first invalid underscore
237 */
238 size_t
239 pm_strspn_decimal_numbercxx . . $ pm_strspn_decimal_number(2f92041e72109b76).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length, const uint8_tcxx . . $ uint8_t# **invalid) {
240 return pm_strspn_number_kind_underscorescxx . . $ pm_strspn_number_kind_underscores(86457d1d07599b5c).(string, length, invalid, PRISM_NUMBER_BIT_DECIMAL_NUMBERcxx . . $ `src/util/pm_char.c:12:9`!);
241 }
242
243 /**
244 * Returns the number of characters at the start of the string that are
245 * hexadecimal digits. Disallows searching past the given maximum number of
246 * characters.
247 */
248 size_t
249 pm_strspn_hexadecimal_digitcxx . . $ pm_strspn_hexadecimal_digit(dc9dc2cf7fc514b1).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length) {
250 return pm_strspn_number_kindcxx . . $ pm_strspn_number_kind(9e2afee6ff424c3d).(string, length, PRISM_NUMBER_BIT_HEXADECIMAL_DIGITcxx . . $ `src/util/pm_char.c:13:9`!);
251 }
252
253 /**
254 * Returns the number of characters at the start of the string that are
255 * hexadecimal digits or underscores. Disallows searching past the given maximum
256 * number of characters.
257 *
258 * If multiple underscores are found in a row or if an underscore is
259 * found at the end of the number, then the invalid pointer is set to the index
260 * of the first invalid underscore.
261 */
262 size_t
263 pm_strspn_hexadecimal_numbercxx . . $ pm_strspn_hexadecimal_number(2f92041e72109b76).(const uint8_tcxx . . $ uint8_t# *string, ptrdiff_t length, const uint8_tcxx . . $ uint8_t# **invalid) {
264 return pm_strspn_number_kind_underscorescxx . . $ pm_strspn_number_kind_underscores(86457d1d07599b5c).(string, length, invalid, PRISM_NUMBER_BIT_HEXADECIMAL_NUMBERcxx . . $ `src/util/pm_char.c:14:9`!);
265 }
266
267 /**
268 * Returns true if the given character matches the given kind.
269 */
270 static inline boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
271 pm_char_is_number_kindcxx . . $ pm_char_is_number_kind(4ed805b44025c28a).(const uint8_tcxx . . $ uint8_t# b, uint8_tcxx . . $ uint8_t# kind) {
272 return (pm_number_tablecxx . . $ pm_number_table.[b] & kind) != 0;
273 }
274
275 /**
276 * Returns true if the given character is a binary digit.
277 */
278 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
279 pm_char_is_binary_digitcxx . . $ pm_char_is_binary_digit(cef82f9be00a201a).(const uint8_tcxx . . $ uint8_t# b) {
280 return pm_char_is_number_kindcxx . . $ pm_char_is_number_kind(4ed805b44025c28a).(b, PRISM_NUMBER_BIT_BINARY_DIGITcxx . . $ `src/util/pm_char.c:7:9`!);
281 }
282
283 /**
284 * Returns true if the given character is an octal digit.
285 */
286 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
287 pm_char_is_octal_digitcxx . . $ pm_char_is_octal_digit(cef82f9be00a201a).(const uint8_tcxx . . $ uint8_t# b) {
288 return pm_char_is_number_kindcxx . . $ pm_char_is_number_kind(4ed805b44025c28a).(b, PRISM_NUMBER_BIT_OCTAL_DIGITcxx . . $ `src/util/pm_char.c:9:9`!);
289 }
290
291 /**
292 * Returns true if the given character is a decimal digit.
293 */
294 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
295 pm_char_is_decimal_digitcxx . . $ pm_char_is_decimal_digit(cef82f9be00a201a).(const uint8_tcxx . . $ uint8_t# b) {
296 return pm_char_is_number_kindcxx . . $ pm_char_is_number_kind(4ed805b44025c28a).(b, PRISM_NUMBER_BIT_DECIMAL_DIGITcxx . . $ `src/util/pm_char.c:11:9`!);
297 }
298
299 /**
300 * Returns true if the given character is a hexadecimal digit.
301 */
302 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`!
303 pm_char_is_hexadecimal_digitcxx . . $ pm_char_is_hexadecimal_digit(cef82f9be00a201a).(const uint8_tcxx . . $ uint8_t# b) {
304 return pm_char_is_number_kindcxx . . $ pm_char_is_number_kind(4ed805b44025c28a).(b, PRISM_NUMBER_BIT_HEXADECIMAL_DIGITcxx . . $ `src/util/pm_char.c:13:9`!);
305 }
306
307 #undef PRISM_CHAR_BIT_WHITESPACEcxx . . $ `src/util/pm_char.c:3:9`!
308 #undef PRISM_CHAR_BIT_INLINE_WHITESPACEcxx . . $ `src/util/pm_char.c:4:9`!
309 #undef PRISM_CHAR_BIT_REGEXP_OPTIONcxx . . $ `src/util/pm_char.c:5:9`!
310
311 #undef PRISM_NUMBER_BIT_BINARY_DIGITcxx . . $ `src/util/pm_char.c:7:9`!
312 #undef PRISM_NUMBER_BIT_BINARY_NUMBERcxx . . $ `src/util/pm_char.c:8:9`!
313 #undef PRISM_NUMBER_BIT_OCTAL_DIGITcxx . . $ `src/util/pm_char.c:9:9`!
314 #undef PRISM_NUMBER_BIT_OCTAL_NUMBERcxx . . $ `src/util/pm_char.c:10:9`!
315 #undef PRISM_NUMBER_BIT_DECIMAL_DIGITcxx . . $ `src/util/pm_char.c:11:9`!
316 #undef PRISM_NUMBER_BIT_DECIMAL_NUMBERcxx . . $ `src/util/pm_char.c:12:9`!
317 #undef PRISM_NUMBER_BIT_HEXADECIMAL_NUMBERcxx . . $ `src/util/pm_char.c:14:9`!
318 #undef PRISM_NUMBER_BIT_HEXADECIMAL_DIGITcxx . . $ `src/util/pm_char.c:13:9`!