package core:text/match
Overview
A Lua-like string match algorithm.
Index
Constants (5)
Variables (1)
Procedure Groups (2)
Types
Error ¶
Error :: enum int { OK, OOB, Invalid_Capture_Index, Invalid_Pattern_Capture, Unfinished_Capture, Malformed_Pattern, Rune_Error, Match_Invalid, }
Match_State ¶
Related Procedures With Parameters
Matcher ¶
Matcher :: struct { haystack: string, pattern: string, captures: [32]Match, captures_length: int, offset: int, err: Error, // changing content for iterators iter: string, iter_index: int, }
Matcher helper struct that stores optional data you might want to use or not as lua is far more dynamic this helps dealing with too much data this also allows use of find/match/gmatch at through one struct
Related Procedures With Parameters
Constants
CAP_POSITION ¶
CAP_POSITION :: -2
CAP_UNFINISHED ¶
CAP_UNFINISHED :: -1
INVALID ¶
INVALID :: -1
L_ESC ¶
L_ESC :: '%'
MAX_CAPTURES ¶
MAX_CAPTURES :: 32
Variables
SPECIALS_TABLE ¶
@(rodata) SPECIALS_TABLE: [256]bool = …
SPECIALS := "^$*+?.([%-" all special characters inside a small ascii array
Procedures
capture_to_close ¶
@(require_results) capture_to_close :: proc(ms: ^Match_State) -> (int, Error) {…}
check_capture ¶
@(require_results) check_capture :: proc(ms: ^Match_State, l: rune) -> (int, Error) {…}
class_end ¶
@(require_results) class_end :: proc(ms: ^Match_State, p: int) -> (step: int, err: Error) {…}
end_capture ¶
@(require_results) end_capture :: proc(ms: ^Match_State, s, p: int) -> (res: int, err: Error) {…}
find_aux ¶
find_aux :: proc( haystack, pattern: string, offset: int, allow_memfind: bool, matches: ^[32]Match, ) -> (captures: int, err: Error) {…}
find a pattern with in a haystack with an offset allow_memfind will speed up simple searches
gfind ¶
@(require_results) gfind :: proc( haystack: ^string, pattern: string, captures: ^[32]Match, ) -> (res: string, ok: bool) {…}
iterative find with zeroth capture only assumes captures is zeroed on first iteration resets captures to zero on last iteration
gmatch ¶
@(require_results) gmatch :: proc( haystack: ^string, pattern: string, captures: ^[32]Match, ) -> (res: string, ok: bool) {…}
iterative matching which returns the 0th/1st match rest has to be used from captures assumes captures is zeroed on first iteration resets captures to zero on last iteration
gsub_allocator ¶
@(require_results) gsub_allocator :: proc( haystack, pattern, replace: string, allocator := context.allocator, ) -> string {…}
uses temp builder to build initial string - then allocates the result
gsub_builder ¶
@(require_results) gsub_builder :: proc(builder: ^strings.Builder, haystack, pattern, replace: string) -> string {…}
gsub with builder, replace patterns found with the replace content
gsub_with ¶
call a procedure on every match in the haystack
index_special ¶
helper call to quick search for special characters
is_alpha ¶
is_alpha :: unicode.is_letter
Return true if the rune r is a letter. Being a letter means that the rune has
the Unicode general category property of L. In practice, the character will have
a general category property of Ll, Lm, Lo, Lt, or Lu.
Inputs:
- r The rune which will be check for having the property of being a letter.
Returns:
true when the rune r is a letter. false will be returned in all other cases.
is_cntrl ¶
is_cntrl :: unicode.is_control
is_cont ¶
continuation byte?
is_digit ¶
is_digit :: unicode.is_digit
This function determincs if a rune is a digit. To be a digit the charage either has a Numeric_Type of Digit or Decimal.
Inputs:
- r The rune to check if it is a digit.
Returns:
true if the rune r is a digit, false in all other cases
is_lower ¶
is_lower :: unicode.is_lower
is_punct ¶
is_punct :: unicode.is_punct
is_space ¶
is_space :: unicode.is_space
is_upper ¶
is_upper :: unicode.is_upper
match ¶
@(require_results) match :: proc(ms: ^Match_State, s, p: int) -> (unused: int, err: Error) {…}
match_balance ¶
@(require_results) match_balance :: proc(ms: ^Match_State, s, p: int) -> (unused: int, err: Error) {…}
match_bracket_class ¶
@(require_results) match_bracket_class :: proc(ms: ^Match_State, c: rune, p, ec: int) -> (sig: bool, err: Error) {…}
match_capture ¶
@(require_results) match_capture :: proc(ms: ^Match_State, s: int, char: rune) -> (res: int, err: Error) {…}
match_default ¶
@(require_results) match_default :: proc(ms: ^Match_State, s, p: int) -> (unused: int, err: Error) {…}
matcher_capture ¶
@(require_results) matcher_capture :: proc(matcher: ^Matcher, index: int, loc := #caller_location) -> string {…}
get the capture at the "correct" spot, as spot 0 is reserved for the first match
matcher_capture_raw ¶
@(require_results) matcher_capture_raw :: proc(matcher: ^Matcher, index: int, loc := #caller_location) -> Match {…}
get the raw match out of the captures, skipping spot 0
matcher_captures_slice ¶
get a slice of all valid captures above the first match
matcher_find ¶
find the first match and return the byte start / end position in the string, true on success
matcher_gmatch ¶
matcher_gmatch :: matcher_match_iter
iteratively match the haystack till it cant find any matches
matcher_init ¶
@(require_results) matcher_init :: proc(haystack, pattern: string, offset: int = 0) -> (res: Matcher) {…}
init using haystack & pattern and an optional byte offset
matcher_match ¶
find the first match and return the matched word, true on success
matcher_match_iter ¶
@(require_results) matcher_match_iter :: proc(matcher: ^Matcher) -> (res: string, index: int, ok: bool) {…}
iteratively match the haystack till it cant find any matches
max_expand ¶
@(require_results) max_expand :: proc(ms: ^Match_State, s, p, ep: int) -> (res: int, err: Error) {…}
min_expand ¶
@(require_results) min_expand :: proc(ms: ^Match_State, s, p, ep: int) -> (res: int, err: Error) {…}
pattern_case_insensitive_allocator ¶
@(require_results) pattern_case_insensitive_allocator :: proc( pattern: string, cap: int = 256, allocator := context.allocator, ) -> string {…}
pattern_case_insensitive_builder ¶
@(require_results) pattern_case_insensitive_builder :: proc(builder: ^strings.Builder, pattern: string) -> string {…}
rebuilds a pattern into a case insensitive pattern
push_captures ¶
@(require_results) push_captures :: proc( ms: ^Match_State, s, e: int, matches: []Match, ) -> (nlevels: int, err: Error) {…}
single_match ¶
@(require_results) single_match :: proc( ms: ^Match_State, s, p, ep: int, ) -> (matched: bool, schar_size: int, err: Error) {…}
start_capture ¶
@(require_results) start_capture :: proc(ms: ^Match_State, s, p, what: int) -> (res: int, err: Error) {…}
utf8_advance ¶
find the first utf8 charater and its size and advance the index return an error if the character is an error
utf8_peek ¶
find the first utf8 charater and its size, return an error if the character is an error
Procedure Groups
gsub ¶
gsub :: proc{ gsub_builder, gsub_allocator, }
pattern_case_insensitive ¶
pattern_case_insensitive :: proc{ pattern_case_insensitive_builder, pattern_case_insensitive_allocator, }
Source Files
Generation Information
Generated with odin version dev-2026-10 (vendor "odin") Windows_amd64 @ 2026-10-22 23:49:25.827938400 +0000 UTC