A Lua-like string match algorithm.

Collection Info

View Source
Collection
core
Path
text/match
Entries
56

Source Files

Constants

5

Types

6

Matcher #

Source
Matcher :: Matcher

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

Procedures

42

find_aux #

Source
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 #

Source
@(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 #

Source
@(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 #

Source
@(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 #

Source
@(require_results)
gsub_builder :: proc(builder: ^Builder, haystack, pattern, replace: string) -> string {…}

gsub with builder, replace patterns found with the replace content

index_special #

Source
@(require_results)
index_special :: proc(text: string) -> int {…}

helper call to quick search for special characters

matcher_capture #

Source
@(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 #

Source
@(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 #

Source
@(require_results)
matcher_captures_slice :: proc(matcher: ^Matcher) -> []Match {…}

get a slice of all valid captures above the first match

matcher_find #

Source
@(require_results)
matcher_find :: proc(matcher: ^Matcher) -> (start, end: int, ok: bool) {…}

find the first match and return the byte start / end position in the string, true on success

matcher_gmatch #

Source
@(require_results)
matcher_gmatch :: proc(matcher: ^Matcher) -> (res: string, index: int, ok: bool) {…}

iteratively match the haystack till it cant find any matches

matcher_init #

Source
@(require_results)
matcher_init :: proc(haystack, pattern: string, offset: int = 0) -> (res: Matcher) {…}

init using haystack & pattern and an optional byte offset

matcher_match #

Source
@(require_results)
matcher_match :: proc(matcher: ^Matcher) -> (word: string, ok: bool) {…}

find the first match and return the matched word, true on success

matcher_match_iter #

Source
@(require_results)
matcher_match_iter :: proc(matcher: ^Matcher) -> (res: string, index: int, ok: bool) {…}

iteratively match the haystack till it cant find any matches

pattern_case_insensitive_allocator #

Source
@(require_results)
pattern_case_insensitive_allocator :: proc(pattern: string, cap: int = 256, allocator := context.allocator) -> string {…}

pattern_case_insensitive_builder #

Source
@(require_results)
pattern_case_insensitive_builder :: proc(builder: ^Builder, pattern: string) -> string {…}

rebuilds a pattern into a case insensitive pattern

utf8_advance #

Source
@(require_results)
utf8_advance :: proc(bytes: string, index: ^int) -> (c: rune, err: Error) {…}

find the first utf8 charater and its size and advance the index return an error if the character is an error

utf8_peek #

Source
@(require_results)
utf8_peek :: proc(bytes: string) -> (c: rune, size: int, err: Error) {…}

find the first utf8 charater and its size, return an error if the character is an error

Procedure Groups

2

Variables

1

SPECIALS_TABLE #

Source
@(rodata)
SPECIALS_TABLE: [256]bool = [256]bool{'^' = true, '$' = true, '*' = true, '+' = true, '?' = true, '.' = true, '(' = true, '[' = true, '%' = true, '-' = true}

SPECIALS := "^$*+?.([%-" all special characters inside a small ascii array