Ruby 4.1.0dev (2026-03-20 revision eb04ab9117336f2b3613244cfe8a528c52faf6d6)
pm_char.h
Go to the documentation of this file.
1
6#ifndef PRISM_CHAR_H
7#define PRISM_CHAR_H
8
9#include "prism/defines.h"
11
12#include <stdbool.h>
13#include <stddef.h>
14
16#define PRISM_CHAR_BIT_WHITESPACE (1 << 0)
17
19#define PRISM_CHAR_BIT_INLINE_WHITESPACE (1 << 1)
20
25extern const uint8_t pm_byte_table[256];
26
33static PRISM_FORCE_INLINE bool
34pm_char_is_whitespace(const uint8_t b) {
36}
37
44static PRISM_FORCE_INLINE bool
48
58static PRISM_FORCE_INLINE size_t
59pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length) {
60 if (length <= 0) return 0;
61 size_t size = 0;
62 size_t maximum = (size_t) length;
63 while (size < maximum && (pm_byte_table[string[size]] & PRISM_CHAR_BIT_INLINE_WHITESPACE)) size++;
64 return size;
65}
66
76size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length);
77
92size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_arena_t *arena, pm_line_offset_list_t *line_offsets, uint32_t start_offset);
93
103size_t pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length);
104
115size_t pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length);
116
133size_t pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
134
151size_t pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
152
169size_t pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
170
180size_t pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length);
181
198size_t pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
199
200
207bool pm_char_is_binary_digit(const uint8_t b);
208
215bool pm_char_is_octal_digit(const uint8_t b);
216
223bool pm_char_is_decimal_digit(const uint8_t b);
224
231bool pm_char_is_hexadecimal_digit(const uint8_t b);
232
233#endif
size_t pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length)
Returns the number of characters at the start of the string that are hexadecimal digits.
Definition pm_char.c:215
bool pm_char_is_decimal_digit(const uint8_t b)
Returns true if the given character is a decimal digit.
Definition pm_char.c:261
size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length)
Returns the number of characters at the start of the string that are whitespace.
Definition pm_char.c:74
#define PRISM_CHAR_BIT_INLINE_WHITESPACE
Bit flag for inline whitespace characters in pm_byte_table.
Definition pm_char.h:19
size_t pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_arena_t *arena, pm_line_offset_list_t *line_offsets, uint32_t start_offset)
Returns the number of characters at the start of the string that are whitespace while also tracking t...
Definition pm_char.c:84
static PRISM_FORCE_INLINE bool pm_char_is_inline_whitespace(const uint8_t b)
Returns true if the given character is an inline whitespace character.
Definition pm_char.h:45
size_t pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid)
Returns the number of characters at the start of the string that are hexadecimal digits or underscore...
Definition pm_char.c:229
size_t pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid)
Returns the number of characters at the start of the string that are decimal digits or underscores.
Definition pm_char.c:205
size_t pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length)
Returns the number of characters at the start of the string that are decimal digits.
Definition pm_char.c:191
const uint8_t pm_byte_table[256]
A lookup table for classifying bytes.
Definition pm_char.c:14
size_t pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid)
Returns the number of characters at the start of the string that are binary digits or underscores.
Definition pm_char.c:168
size_t pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid)
Returns the number of characters at the start of the string that are octal digits or underscores.
Definition pm_char.c:182
static PRISM_FORCE_INLINE bool pm_char_is_whitespace(const uint8_t b)
Returns true if the given character is a whitespace character.
Definition pm_char.h:34
bool pm_char_is_hexadecimal_digit(const uint8_t b)
Returns true if the given character is a hexadecimal digit.
Definition pm_char.c:269
static PRISM_FORCE_INLINE size_t pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length)
Returns the number of characters at the start of the string that are inline whitespace (space/tab).
Definition pm_char.h:59
bool pm_char_is_octal_digit(const uint8_t b)
Returns true if the given character is an octal digit.
Definition pm_char.c:253
bool pm_char_is_binary_digit(const uint8_t b)
Returns true if the given character is a binary digit.
Definition pm_char.c:245
#define PRISM_CHAR_BIT_WHITESPACE
Bit flag for whitespace characters in pm_byte_table.
Definition pm_char.h:16
size_t pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length)
Returns the number of characters at the start of the string that are regexp options.
Definition pm_char.c:106
A list of byte offsets of newlines in a string.
Macro definitions used throughout the prism library.
#define PRISM_FORCE_INLINE
Force a function to be inlined at every call site.
Definition defines.h:99
C99 shim for <stdbool.h>
A bump allocator.
Definition pm_arena.h:39
A list of offsets of the start of lines in a string.