debase-ruby_core_source 3.3.0 → 3.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Rakefile +2 -1
  4. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/ast.h +4612 -0
  5. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/defines.h +94 -0
  6. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/diagnostic.h +297 -0
  7. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/encoding.h +248 -0
  8. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/extension.h +18 -0
  9. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/node.h +57 -0
  10. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/options.h +204 -0
  11. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/pack.h +152 -0
  12. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/parser.h +716 -0
  13. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/prettyprint.h +26 -0
  14. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/prism.h +272 -0
  15. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/regexp.h +33 -0
  16. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_buffer.h +146 -0
  17. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_char.h +205 -0
  18. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_constant_pool.h +191 -0
  19. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_list.h +97 -0
  20. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_memchr.h +29 -0
  21. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_newline_list.h +104 -0
  22. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_state_stack.h +42 -0
  23. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_string.h +150 -0
  24. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_string_list.h +44 -0
  25. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_strncasecmp.h +32 -0
  26. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/util/pm_strpbrk.h +43 -0
  27. data/lib/debase/ruby_core_source/ruby-3.3.0-p0/prism/version.h +29 -0
  28. data/lib/debase/ruby_core_source/version.rb +1 -1
  29. metadata +30 -6
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file prettyprint.h
3
+ *
4
+ * An AST node pretty-printer.
5
+ */
6
+ #ifndef PRISM_PRETTYPRINT_H
7
+ #define PRISM_PRETTYPRINT_H
8
+
9
+ #include "prism/defines.h"
10
+
11
+ #include <stdio.h>
12
+
13
+ #include "prism/ast.h"
14
+ #include "prism/parser.h"
15
+ #include "prism/util/pm_buffer.h"
16
+
17
+ /**
18
+ * Pretty-prints the AST represented by the given node to the given buffer.
19
+ *
20
+ * @param output_buffer The buffer to write the pretty-printed AST to.
21
+ * @param parser The parser that parsed the AST.
22
+ * @param node The root node of the AST to pretty-print.
23
+ */
24
+ PRISM_EXPORTED_FUNCTION void pm_prettyprint(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm_node_t *node);
25
+
26
+ #endif
@@ -0,0 +1,272 @@
1
+ /**
2
+ * @file prism.h
3
+ *
4
+ * The main header file for the prism parser.
5
+ */
6
+ #ifndef PRISM_H
7
+ #define PRISM_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/util/pm_buffer.h"
11
+ #include "prism/util/pm_char.h"
12
+ #include "prism/util/pm_memchr.h"
13
+ #include "prism/util/pm_strncasecmp.h"
14
+ #include "prism/util/pm_strpbrk.h"
15
+ #include "prism/ast.h"
16
+ #include "prism/diagnostic.h"
17
+ #include "prism/node.h"
18
+ #include "prism/options.h"
19
+ #include "prism/pack.h"
20
+ #include "prism/parser.h"
21
+ #include "prism/prettyprint.h"
22
+ #include "prism/regexp.h"
23
+ #include "prism/version.h"
24
+
25
+ #include <assert.h>
26
+ #include <errno.h>
27
+ #include <stdarg.h>
28
+ #include <stdbool.h>
29
+ #include <stdint.h>
30
+ #include <stdio.h>
31
+ #include <stdlib.h>
32
+ #include <string.h>
33
+
34
+ #ifndef _WIN32
35
+ #include <strings.h>
36
+ #endif
37
+
38
+ /**
39
+ * The prism version and the serialization format.
40
+ *
41
+ * @returns The prism version as a constant string.
42
+ */
43
+ PRISM_EXPORTED_FUNCTION const char * pm_version(void);
44
+
45
+ /**
46
+ * Initialize a parser with the given start and end pointers.
47
+ *
48
+ * @param parser The parser to initialize.
49
+ * @param source The source to parse.
50
+ * @param size The size of the source.
51
+ * @param options The optional options to use when parsing.
52
+ */
53
+ PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm_options_t *options);
54
+
55
+ /**
56
+ * Register a callback that will be called whenever prism changes the encoding
57
+ * it is using to parse based on the magic comment.
58
+ *
59
+ * @param parser The parser to register the callback with.
60
+ * @param callback The callback to register.
61
+ */
62
+ PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback(pm_parser_t *parser, pm_encoding_changed_callback_t callback);
63
+
64
+ /**
65
+ * Free any memory associated with the given parser.
66
+ *
67
+ * @param parser The parser to free.
68
+ */
69
+ PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser);
70
+
71
+ /**
72
+ * Initiate the parser with the given parser.
73
+ *
74
+ * @param parser The parser to use.
75
+ * @return The AST representing the source.
76
+ */
77
+ PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser);
78
+
79
+ /**
80
+ * Serialize the given list of comments to the given buffer.
81
+ *
82
+ * @param parser The parser to serialize.
83
+ * @param list The list of comments to serialize.
84
+ * @param buffer The buffer to serialize to.
85
+ */
86
+ void pm_serialize_comment_list(pm_parser_t *parser, pm_list_t *list, pm_buffer_t *buffer);
87
+
88
+ /**
89
+ * Serialize the name of the encoding to the buffer.
90
+ *
91
+ * @param encoding The encoding to serialize.
92
+ * @param buffer The buffer to serialize to.
93
+ */
94
+ void pm_serialize_encoding(const pm_encoding_t *encoding, pm_buffer_t *buffer);
95
+
96
+ /**
97
+ * Serialize the encoding, metadata, nodes, and constant pool.
98
+ *
99
+ * @param parser The parser to serialize.
100
+ * @param node The node to serialize.
101
+ * @param buffer The buffer to serialize to.
102
+ */
103
+ void pm_serialize_content(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
104
+
105
+ /**
106
+ * Serialize the AST represented by the given node to the given buffer.
107
+ *
108
+ * @param parser The parser to serialize.
109
+ * @param node The node to serialize.
110
+ * @param buffer The buffer to serialize to.
111
+ */
112
+ PRISM_EXPORTED_FUNCTION void pm_serialize(pm_parser_t *parser, pm_node_t *node, pm_buffer_t *buffer);
113
+
114
+ /**
115
+ * Parse the given source to the AST and dump the AST to the given buffer.
116
+ *
117
+ * @param buffer The buffer to serialize to.
118
+ * @param source The source to parse.
119
+ * @param size The size of the source.
120
+ * @param data The optional data to pass to the parser.
121
+ */
122
+ PRISM_EXPORTED_FUNCTION void pm_serialize_parse(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
123
+
124
+ /**
125
+ * Parse and serialize the comments in the given source to the given buffer.
126
+ *
127
+ * @param buffer The buffer to serialize to.
128
+ * @param source The source to parse.
129
+ * @param size The size of the source.
130
+ * @param data The optional data to pass to the parser.
131
+ */
132
+ PRISM_EXPORTED_FUNCTION void pm_serialize_parse_comments(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
133
+
134
+ /**
135
+ * Lex the given source and serialize to the given buffer.
136
+ *
137
+ * @param source The source to lex.
138
+ * @param size The size of the source.
139
+ * @param buffer The buffer to serialize to.
140
+ * @param data The optional data to pass to the lexer.
141
+ */
142
+ PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
143
+
144
+ /**
145
+ * Parse and serialize both the AST and the tokens represented by the given
146
+ * source to the given buffer.
147
+ *
148
+ * @param buffer The buffer to serialize to.
149
+ * @param source The source to parse.
150
+ * @param size The size of the source.
151
+ * @param data The optional data to pass to the parser.
152
+ */
153
+ PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
154
+
155
+ /**
156
+ * Parse the source and return true if it parses without errors or warnings.
157
+ *
158
+ * @param source The source to parse.
159
+ * @param size The size of the source.
160
+ * @param data The optional data to pass to the parser.
161
+ * @return True if the source parses without errors or warnings.
162
+ */
163
+ PRISM_EXPORTED_FUNCTION bool pm_parse_success_p(const uint8_t *source, size_t size, const char *data);
164
+
165
+ /**
166
+ * Returns a string representation of the given token type.
167
+ *
168
+ * @param token_type The token type to convert to a string.
169
+ * @return A string representation of the given token type.
170
+ */
171
+ PRISM_EXPORTED_FUNCTION const char * pm_token_type_to_str(pm_token_type_t token_type);
172
+
173
+ /**
174
+ * @mainpage
175
+ *
176
+ * Prism is a parser for the Ruby programming language. It is designed to be
177
+ * portable, error tolerant, and maintainable. It is written in C99 and has no
178
+ * dependencies. It is currently being integrated into
179
+ * [CRuby](https://github.com/ruby/ruby),
180
+ * [JRuby](https://github.com/jruby/jruby),
181
+ * [TruffleRuby](https://github.com/oracle/truffleruby),
182
+ * [Sorbet](https://github.com/sorbet/sorbet), and
183
+ * [Syntax Tree](https://github.com/ruby-syntax-tree/syntax_tree).
184
+ *
185
+ * @section getting-started Getting started
186
+ *
187
+ * If you're vendoring this project and compiling it statically then as long as
188
+ * you have a C99 compiler you will be fine. If you're linking against it as
189
+ * shared library, then you should compile with `-fvisibility=hidden` and
190
+ * `-DPRISM_EXPORT_SYMBOLS` to tell prism to make only its public interface
191
+ * visible.
192
+ *
193
+ * @section parsing Parsing
194
+ *
195
+ * In order to parse Ruby code, the structures and functions that you're going
196
+ * to want to use and be aware of are:
197
+ *
198
+ * * `pm_parser_t` - the main parser structure
199
+ * * `pm_parser_init` - initialize a parser
200
+ * * `pm_parse` - parse and return the root node
201
+ * * `pm_node_destroy` - deallocate the root node returned by `pm_parse`
202
+ * * `pm_parser_free` - free the internal memory of the parser
203
+ *
204
+ * Putting all of this together would look something like:
205
+ *
206
+ * ```c
207
+ * void parse(const uint8_t *source, size_t length) {
208
+ * pm_parser_t parser;
209
+ * pm_parser_init(&parser, source, length, NULL);
210
+ *
211
+ * pm_node_t *root = pm_parse(&parser);
212
+ * printf("PARSED!\n");
213
+ *
214
+ * pm_node_destroy(&parser, root);
215
+ * pm_parser_free(&parser);
216
+ * }
217
+ * ```
218
+ *
219
+ * All of the nodes "inherit" from `pm_node_t` by embedding those structures as
220
+ * their first member. This means you can downcast and upcast any node in the
221
+ * tree to a `pm_node_t`.
222
+ *
223
+ * @section serializing Serializing
224
+ *
225
+ * Prism provides the ability to serialize the AST and its related metadata into
226
+ * a binary format. This format is designed to be portable to different
227
+ * languages and runtimes so that you only need to make one FFI call in order to
228
+ * parse Ruby code. The structures and functions that you're going to want to
229
+ * use and be aware of are:
230
+ *
231
+ * * `pm_buffer_t` - a small buffer object that will hold the serialized AST
232
+ * * `pm_buffer_free` - free the memory associated with the buffer
233
+ * * `pm_serialize` - serialize the AST into a buffer
234
+ * * `pm_serialize_parse` - parse and serialize the AST into a buffer
235
+ *
236
+ * Putting all of this together would look something like:
237
+ *
238
+ * ```c
239
+ * void serialize(const uint8_t *source, size_t length) {
240
+ * pm_buffer_t buffer = { 0 };
241
+ *
242
+ * pm_serialize_parse(&buffer, source, length, NULL);
243
+ * printf("SERIALIZED!\n");
244
+ *
245
+ * pm_buffer_free(&buffer);
246
+ * }
247
+ * ```
248
+ *
249
+ * @section inspecting Inspecting
250
+ *
251
+ * Prism provides the ability to inspect the AST by pretty-printing nodes. You
252
+ * can do this with the `pm_prettyprint` function, which you would use like:
253
+ *
254
+ * ```c
255
+ * void prettyprint(const uint8_t *source, size_t length) {
256
+ * pm_parser_t parser;
257
+ * pm_parser_init(&parser, source, length, NULL);
258
+ *
259
+ * pm_node_t *root = pm_parse(&parser);
260
+ * pm_buffer_t buffer = { 0 };
261
+ *
262
+ * pm_prettyprint(&buffer, &parser, root);
263
+ * printf("*.s%\n", (int) buffer.length, buffer.value);
264
+ *
265
+ * pm_buffer_free(&buffer);
266
+ * pm_node_destroy(&parser, root);
267
+ * pm_parser_free(&parser);
268
+ * }
269
+ * ```
270
+ */
271
+
272
+ #endif
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @file regexp.h
3
+ *
4
+ * A regular expression parser.
5
+ */
6
+ #ifndef PRISM_REGEXP_H
7
+ #define PRISM_REGEXP_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/parser.h"
11
+ #include "prism/encoding.h"
12
+ #include "prism/util/pm_memchr.h"
13
+ #include "prism/util/pm_string_list.h"
14
+ #include "prism/util/pm_string.h"
15
+
16
+ #include <stdbool.h>
17
+ #include <stddef.h>
18
+ #include <string.h>
19
+
20
+ /**
21
+ * Parse a regular expression and extract the names of all of the named capture
22
+ * groups.
23
+ *
24
+ * @param source The source code to parse.
25
+ * @param size The size of the source code.
26
+ * @param named_captures The list to add the names of the named capture groups.
27
+ * @param encoding_changed Whether or not the encoding changed from the default.
28
+ * @param encoding The encoding of the source code.
29
+ * @return Whether or not the parsing was successful.
30
+ */
31
+ PRISM_EXPORTED_FUNCTION bool pm_regexp_named_capture_group_names(const uint8_t *source, size_t size, pm_string_list_t *named_captures, bool encoding_changed, const pm_encoding_t *encoding);
32
+
33
+ #endif
@@ -0,0 +1,146 @@
1
+ /**
2
+ * @file pm_buffer.h
3
+ *
4
+ * A wrapper around a contiguous block of allocated memory.
5
+ */
6
+ #ifndef PRISM_BUFFER_H
7
+ #define PRISM_BUFFER_H
8
+
9
+ #include "prism/defines.h"
10
+
11
+ #include <assert.h>
12
+ #include <stdbool.h>
13
+ #include <stdint.h>
14
+ #include <stdlib.h>
15
+ #include <string.h>
16
+
17
+ /**
18
+ * A pm_buffer_t is a simple memory buffer that stores data in a contiguous
19
+ * block of memory.
20
+ */
21
+ typedef struct {
22
+ /** The length of the buffer in bytes. */
23
+ size_t length;
24
+
25
+ /** The capacity of the buffer in bytes that has been allocated. */
26
+ size_t capacity;
27
+
28
+ /** A pointer to the start of the buffer. */
29
+ char *value;
30
+ } pm_buffer_t;
31
+
32
+ /**
33
+ * Return the size of the pm_buffer_t struct.
34
+ *
35
+ * @returns The size of the pm_buffer_t struct.
36
+ */
37
+ PRISM_EXPORTED_FUNCTION size_t pm_buffer_sizeof(void);
38
+
39
+ /**
40
+ * Initialize a pm_buffer_t with the given capacity.
41
+ *
42
+ * @param buffer The buffer to initialize.
43
+ * @param capacity The capacity of the buffer.
44
+ * @returns True if the buffer was initialized successfully, false otherwise.
45
+ */
46
+ bool pm_buffer_init_capacity(pm_buffer_t *buffer, size_t capacity);
47
+
48
+ /**
49
+ * Initialize a pm_buffer_t with its default values.
50
+ *
51
+ * @param buffer The buffer to initialize.
52
+ * @returns True if the buffer was initialized successfully, false otherwise.
53
+ */
54
+ PRISM_EXPORTED_FUNCTION bool pm_buffer_init(pm_buffer_t *buffer);
55
+
56
+ /**
57
+ * Return the value of the buffer.
58
+ *
59
+ * @param buffer The buffer to get the value of.
60
+ * @returns The value of the buffer.
61
+ */
62
+ PRISM_EXPORTED_FUNCTION char * pm_buffer_value(pm_buffer_t *buffer);
63
+
64
+ /**
65
+ * Return the length of the buffer.
66
+ *
67
+ * @param buffer The buffer to get the length of.
68
+ * @returns The length of the buffer.
69
+ */
70
+ PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(pm_buffer_t *buffer);
71
+
72
+ /**
73
+ * Append the given amount of space as zeroes to the buffer.
74
+ *
75
+ * @param buffer The buffer to append to.
76
+ * @param length The amount of space to append and zero.
77
+ */
78
+ void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length);
79
+
80
+ /**
81
+ * Append a formatted string to the buffer.
82
+ *
83
+ * @param buffer The buffer to append to.
84
+ * @param format The format string to append.
85
+ * @param ... The arguments to the format string.
86
+ */
87
+ void pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) PRISM_ATTRIBUTE_FORMAT(2, 3);
88
+
89
+ /**
90
+ * Append a string to the buffer.
91
+ *
92
+ * @param buffer The buffer to append to.
93
+ * @param value The string to append.
94
+ * @param length The length of the string to append.
95
+ */
96
+ void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length);
97
+
98
+ /**
99
+ * Append a list of bytes to the buffer.
100
+ *
101
+ * @param buffer The buffer to append to.
102
+ * @param value The bytes to append.
103
+ * @param length The length of the bytes to append.
104
+ */
105
+ void pm_buffer_append_bytes(pm_buffer_t *buffer, const uint8_t *value, size_t length);
106
+
107
+ /**
108
+ * Append a single byte to the buffer.
109
+ *
110
+ * @param buffer The buffer to append to.
111
+ * @param value The byte to append.
112
+ */
113
+ void pm_buffer_append_byte(pm_buffer_t *buffer, uint8_t value);
114
+
115
+ /**
116
+ * Append a 32-bit unsigned integer to the buffer as a variable-length integer.
117
+ *
118
+ * @param buffer The buffer to append to.
119
+ * @param value The integer to append.
120
+ */
121
+ void pm_buffer_append_varuint(pm_buffer_t *buffer, uint32_t value);
122
+
123
+ /**
124
+ * Append a 32-bit signed integer to the buffer as a variable-length integer.
125
+ *
126
+ * @param buffer The buffer to append to.
127
+ * @param value The integer to append.
128
+ */
129
+ void pm_buffer_append_varsint(pm_buffer_t *buffer, int32_t value);
130
+
131
+ /**
132
+ * Concatenate one buffer onto another.
133
+ *
134
+ * @param destination The buffer to concatenate onto.
135
+ * @param source The buffer to concatenate.
136
+ */
137
+ void pm_buffer_concat(pm_buffer_t *destination, const pm_buffer_t *source);
138
+
139
+ /**
140
+ * Free the memory associated with the buffer.
141
+ *
142
+ * @param buffer The buffer to free.
143
+ */
144
+ PRISM_EXPORTED_FUNCTION void pm_buffer_free(pm_buffer_t *buffer);
145
+
146
+ #endif
@@ -0,0 +1,205 @@
1
+ /**
2
+ * @file pm_char.h
3
+ *
4
+ * Functions for working with characters and strings.
5
+ */
6
+ #ifndef PRISM_CHAR_H
7
+ #define PRISM_CHAR_H
8
+
9
+ #include "prism/defines.h"
10
+ #include "prism/util/pm_newline_list.h"
11
+
12
+ #include <stdbool.h>
13
+ #include <stddef.h>
14
+
15
+ /**
16
+ * Returns the number of characters at the start of the string that are
17
+ * whitespace. Disallows searching past the given maximum number of characters.
18
+ *
19
+ * @param string The string to search.
20
+ * @param length The maximum number of characters to search.
21
+ * @return The number of characters at the start of the string that are
22
+ * whitespace.
23
+ */
24
+ size_t pm_strspn_whitespace(const uint8_t *string, ptrdiff_t length);
25
+
26
+ /**
27
+ * Returns the number of characters at the start of the string that are
28
+ * whitespace while also tracking the location of each newline. Disallows
29
+ * searching past the given maximum number of characters.
30
+ *
31
+ * @param string The string to search.
32
+ * @param length The maximum number of characters to search.
33
+ * @param newline_list The list of newlines to populate.
34
+ * @return The number of characters at the start of the string that are
35
+ * whitespace.
36
+ */
37
+ size_t
38
+ pm_strspn_whitespace_newlines(const uint8_t *string, ptrdiff_t length, pm_newline_list_t *newline_list);
39
+
40
+ /**
41
+ * Returns the number of characters at the start of the string that are inline
42
+ * whitespace. Disallows searching past the given maximum number of characters.
43
+ *
44
+ * @param string The string to search.
45
+ * @param length The maximum number of characters to search.
46
+ * @return The number of characters at the start of the string that are inline
47
+ * whitespace.
48
+ */
49
+ size_t pm_strspn_inline_whitespace(const uint8_t *string, ptrdiff_t length);
50
+
51
+ /**
52
+ * Returns the number of characters at the start of the string that are decimal
53
+ * digits. Disallows searching past the given maximum number of characters.
54
+ *
55
+ * @param string The string to search.
56
+ * @param length The maximum number of characters to search.
57
+ * @return The number of characters at the start of the string that are decimal
58
+ * digits.
59
+ */
60
+ size_t pm_strspn_decimal_digit(const uint8_t *string, ptrdiff_t length);
61
+
62
+ /**
63
+ * Returns the number of characters at the start of the string that are
64
+ * hexadecimal digits. Disallows searching past the given maximum number of
65
+ * characters.
66
+ *
67
+ * @param string The string to search.
68
+ * @param length The maximum number of characters to search.
69
+ * @return The number of characters at the start of the string that are
70
+ * hexadecimal digits.
71
+ */
72
+ size_t pm_strspn_hexadecimal_digit(const uint8_t *string, ptrdiff_t length);
73
+
74
+ /**
75
+ * Returns the number of characters at the start of the string that are octal
76
+ * digits or underscores. Disallows searching past the given maximum number of
77
+ * characters.
78
+ *
79
+ * If multiple underscores are found in a row or if an underscore is
80
+ * found at the end of the number, then the invalid pointer is set to the index
81
+ * of the first invalid underscore.
82
+ *
83
+ * @param string The string to search.
84
+ * @param length The maximum number of characters to search.
85
+ * @param invalid The pointer to set to the index of the first invalid
86
+ * underscore.
87
+ * @return The number of characters at the start of the string that are octal
88
+ * digits or underscores.
89
+ */
90
+ size_t pm_strspn_octal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
91
+
92
+ /**
93
+ * Returns the number of characters at the start of the string that are decimal
94
+ * digits or underscores. Disallows searching past the given maximum number of
95
+ * characters.
96
+ *
97
+ * If multiple underscores are found in a row or if an underscore is
98
+ * found at the end of the number, then the invalid pointer is set to the index
99
+ * of the first invalid underscore.
100
+ *
101
+ * @param string The string to search.
102
+ * @param length The maximum number of characters to search.
103
+ * @param invalid The pointer to set to the index of the first invalid
104
+ * underscore.
105
+ * @return The number of characters at the start of the string that are decimal
106
+ * digits or underscores.
107
+ */
108
+ size_t pm_strspn_decimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
109
+
110
+ /**
111
+ * Returns the number of characters at the start of the string that are
112
+ * hexadecimal digits or underscores. Disallows searching past the given maximum
113
+ * number of characters.
114
+ *
115
+ * If multiple underscores are found in a row or if an underscore is
116
+ * found at the end of the number, then the invalid pointer is set to the index
117
+ * of the first invalid underscore.
118
+ *
119
+ * @param string The string to search.
120
+ * @param length The maximum number of characters to search.
121
+ * @param invalid The pointer to set to the index of the first invalid
122
+ * underscore.
123
+ * @return The number of characters at the start of the string that are
124
+ * hexadecimal digits or underscores.
125
+ */
126
+ size_t pm_strspn_hexadecimal_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
127
+
128
+ /**
129
+ * Returns the number of characters at the start of the string that are regexp
130
+ * options. Disallows searching past the given maximum number of characters.
131
+ *
132
+ * @param string The string to search.
133
+ * @param length The maximum number of characters to search.
134
+ * @return The number of characters at the start of the string that are regexp
135
+ * options.
136
+ */
137
+ size_t pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length);
138
+
139
+ /**
140
+ * Returns the number of characters at the start of the string that are binary
141
+ * digits or underscores. Disallows searching past the given maximum number of
142
+ * characters.
143
+ *
144
+ * If multiple underscores are found in a row or if an underscore is
145
+ * found at the end of the number, then the invalid pointer is set to the index
146
+ * of the first invalid underscore.
147
+ *
148
+ * @param string The string to search.
149
+ * @param length The maximum number of characters to search.
150
+ * @param invalid The pointer to set to the index of the first invalid
151
+ * underscore.
152
+ * @return The number of characters at the start of the string that are binary
153
+ * digits or underscores.
154
+ */
155
+ size_t pm_strspn_binary_number(const uint8_t *string, ptrdiff_t length, const uint8_t **invalid);
156
+
157
+ /**
158
+ * Returns true if the given character is a whitespace character.
159
+ *
160
+ * @param b The character to check.
161
+ * @return True if the given character is a whitespace character.
162
+ */
163
+ bool pm_char_is_whitespace(const uint8_t b);
164
+
165
+ /**
166
+ * Returns true if the given character is an inline whitespace character.
167
+ *
168
+ * @param b The character to check.
169
+ * @return True if the given character is an inline whitespace character.
170
+ */
171
+ bool pm_char_is_inline_whitespace(const uint8_t b);
172
+
173
+ /**
174
+ * Returns true if the given character is a binary digit.
175
+ *
176
+ * @param b The character to check.
177
+ * @return True if the given character is a binary digit.
178
+ */
179
+ bool pm_char_is_binary_digit(const uint8_t b);
180
+
181
+ /**
182
+ * Returns true if the given character is an octal digit.
183
+ *
184
+ * @param b The character to check.
185
+ * @return True if the given character is an octal digit.
186
+ */
187
+ bool pm_char_is_octal_digit(const uint8_t b);
188
+
189
+ /**
190
+ * Returns true if the given character is a decimal digit.
191
+ *
192
+ * @param b The character to check.
193
+ * @return True if the given character is a decimal digit.
194
+ */
195
+ bool pm_char_is_decimal_digit(const uint8_t b);
196
+
197
+ /**
198
+ * Returns true if the given character is a hexadecimal digit.
199
+ *
200
+ * @param b The character to check.
201
+ * @return True if the given character is a hexadecimal digit.
202
+ */
203
+ bool pm_char_is_hexadecimal_digit(const uint8_t b);
204
+
205
+ #endif