Ruby 4.1.0dev (2026-09-14 revision 6ca2b168f3790e4972a01686f16f6b82524c699a)
strpbrk.h
1#ifndef PRISM_INTERNAL_STRPBRK_H
2#define PRISM_INTERNAL_STRPBRK_H
3
4#include "prism/parser.h"
5
6/* The maximum number of bytes in a strpbrk charset. */
7#define PM_STRPBRK_CACHE_SIZE 16
8
9#include <stddef.h>
10#include <stdint.h>
11
12/*
13 * Here we have rolled our own version of strpbrk. The standard library strpbrk
14 * has undefined behavior when the source string is not null-terminated. We want
15 * to support strings that are not null-terminated because pm_parse does not
16 * have the contract that the string is null-terminated. (This is desirable
17 * because it means the extension can call pm_parse with the result of a call to
18 * mmap).
19 *
20 * The standard library strpbrk also does not support passing a maximum length
21 * to search. We want to support this for the reason mentioned above, but we
22 * also don't want it to stop on null bytes. Ruby actually allows null bytes
23 * within strings, comments, regular expressions, etc. So we need to be able to
24 * skip past them.
25 *
26 * Finally, we want to support encodings wherein the charset could contain
27 * characters that are trailing bytes of multi-byte characters. For example, in
28 * Shift-JIS, the backslash character can be a trailing byte. In that case we
29 * need to take a slower path and iterate one multi-byte character at a time.
30 */
31const uint8_t * pm_strpbrk(pm_parser_t *parser, const uint8_t *source, const uint8_t *charset, ptrdiff_t length, bool validate);
32
33#endif
The parser used to parse Ruby source.