3#define PRISM_CHAR_BIT_REGEXP_OPTION (1 << 2)
5#define PRISM_NUMBER_BIT_BINARY_DIGIT (1 << 0)
6#define PRISM_NUMBER_BIT_BINARY_NUMBER (1 << 1)
7#define PRISM_NUMBER_BIT_OCTAL_DIGIT (1 << 2)
8#define PRISM_NUMBER_BIT_OCTAL_NUMBER (1 << 3)
9#define PRISM_NUMBER_BIT_DECIMAL_DIGIT (1 << 4)
10#define PRISM_NUMBER_BIT_DECIMAL_NUMBER (1 << 5)
11#define PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT (1 << 6)
12#define PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER (1 << 7)
14const uint8_t pm_byte_table[256] = {
16 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 3, 3, 3, 0, 0,
17 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
21 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0,
22 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
23 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0,
24 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
28 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34static const uint8_t pm_number_table[256] = {
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
39 0xff, 0xff, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
40 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa,
42 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
47 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
48 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
49 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59pm_strspn_char_kind(
const uint8_t *
string, ptrdiff_t length, uint8_t kind) {
60 if (length <= 0)
return 0;
63 size_t maximum = (size_t) length;
65 while (size < maximum && (pm_byte_table[
string[size]] & kind)) size++;
74pm_strspn_whitespace(
const uint8_t *
string, ptrdiff_t length) {
85 if (length <= 0)
return 0;
88 uint32_t maximum = (uint32_t) length;
91 if (
string[size] ==
'\n') {
106pm_strspn_regexp_option(
const uint8_t *
string, ptrdiff_t length) {
107 return pm_strspn_char_kind(
string, length, PRISM_CHAR_BIT_REGEXP_OPTION);
117pm_strspn_number_kind(
const uint8_t *
string, ptrdiff_t length, uint8_t kind) {
118 if (length <= 0)
return 0;
121 size_t maximum = (size_t) length;
123 while (size < maximum && (pm_number_table[
string[size]] & kind)) size++;
136pm_strspn_number_kind_underscores(
const uint8_t *
string, ptrdiff_t length,
const uint8_t **invalid, uint8_t kind) {
137 if (length <= 0)
return 0;
140 size_t maximum = (size_t) length;
142 bool underscore =
false;
143 while (size < maximum && (pm_number_table[
string[size]] & kind)) {
144 if (
string[size] ==
'_') {
145 if (underscore) *invalid =
string + size;
154 if (size > 0 &&
string[size - 1] ==
'_') *invalid =
string + size - 1;
168pm_strspn_binary_number(
const uint8_t *
string, ptrdiff_t length,
const uint8_t **invalid) {
169 return pm_strspn_number_kind_underscores(
string, length, invalid, PRISM_NUMBER_BIT_BINARY_NUMBER);
182pm_strspn_octal_number(
const uint8_t *
string, ptrdiff_t length,
const uint8_t **invalid) {
183 return pm_strspn_number_kind_underscores(
string, length, invalid, PRISM_NUMBER_BIT_OCTAL_NUMBER);
191pm_strspn_decimal_digit(
const uint8_t *
string, ptrdiff_t length) {
192 return pm_strspn_number_kind(
string, length, PRISM_NUMBER_BIT_DECIMAL_DIGIT);
205pm_strspn_decimal_number(
const uint8_t *
string, ptrdiff_t length,
const uint8_t **invalid) {
206 return pm_strspn_number_kind_underscores(
string, length, invalid, PRISM_NUMBER_BIT_DECIMAL_NUMBER);
215pm_strspn_hexadecimal_digit(
const uint8_t *
string, ptrdiff_t length) {
216 return pm_strspn_number_kind(
string, length, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT);
229pm_strspn_hexadecimal_number(
const uint8_t *
string, ptrdiff_t length,
const uint8_t **invalid) {
230 return pm_strspn_number_kind_underscores(
string, length, invalid, PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER);
237pm_char_is_number_kind(
const uint8_t b, uint8_t kind) {
238 return (pm_number_table[b] & kind) != 0;
245pm_char_is_binary_digit(
const uint8_t b) {
246 return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_BINARY_DIGIT);
253pm_char_is_octal_digit(
const uint8_t b) {
254 return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_OCTAL_DIGIT);
261pm_char_is_decimal_digit(
const uint8_t b) {
262 return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_DECIMAL_DIGIT);
269pm_char_is_hexadecimal_digit(
const uint8_t b) {
270 return pm_char_is_number_kind(b, PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT);
273#undef PRISM_CHAR_BIT_WHITESPACE
274#undef PRISM_CHAR_BIT_INLINE_WHITESPACE
275#undef PRISM_CHAR_BIT_REGEXP_OPTION
277#undef PRISM_NUMBER_BIT_BINARY_DIGIT
278#undef PRISM_NUMBER_BIT_BINARY_NUMBER
279#undef PRISM_NUMBER_BIT_OCTAL_DIGIT
280#undef PRISM_NUMBER_BIT_OCTAL_NUMBER
281#undef PRISM_NUMBER_BIT_DECIMAL_DIGIT
282#undef PRISM_NUMBER_BIT_DECIMAL_NUMBER
283#undef PRISM_NUMBER_BIT_HEXADECIMAL_NUMBER
284#undef PRISM_NUMBER_BIT_HEXADECIMAL_DIGIT
Functions for working with characters and strings.
#define PRISM_CHAR_BIT_WHITESPACE
Bit flag for whitespace characters in pm_byte_table.
static PRISM_FORCE_INLINE void pm_line_offset_list_append(pm_arena_t *arena, pm_line_offset_list_t *list, uint32_t cursor)
Append a new offset to the list.
A list of offsets of the start of lines in a string.