1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* Copyright (c) 2025-2026 Anton Kundenko <singaraiona@gmail.com>
* All rights reserved.
*/
/* Glob pattern match, iterative two-pointer (no catastrophic backtracking).
* Worst case O(n*m); typical case linear.
*
* Supported metacharacters:
* * — matches zero or more characters
* ? — matches exactly one character
* [abc] — character class: matches any of a, b, c
* [a-z] — range
* [!abc] — negated class
*
* Matching a literal metacharacter — there is no backslash escape; wrap
* the character in a one-element class instead:
* [*] matches a literal '*'
* [?] matches a literal '?'
* [[] matches a literal '['
* []] matches a literal ']' (']' as first char inside [...] is literal)
* [-] matches a literal '-' (as the sole char, no range to form)
*
* `glob_match` is case-sensitive. `glob_match_ci` lowercases ASCII letters
* on both sides before comparing (so it matches 'A' against 'a', 'A-Z'
* range matches both case forms, etc.).
*
* Lenient parsing policy: an unterminated character class (e.g. pattern
* "abc[def" with no closing `]`) is accepted — the class consumes input
* up to the end of the pattern and the match continues with whatever
* `matched` flag accumulated. This matches glibc fnmatch's permissive
* behaviour and avoids surprising `error: parse` mid-search. Callers
* that want strict validation should pre-validate the pattern. */
bool ;
bool ;
/* RAY_OPS_GLOB_H */