package core:text/match

⌘K
Ctrl+K
or
/

    Types

    Capture ¶

    Capture :: struct {
    	init: int,
    	len:  int,
    }

    Error ¶

    Error :: enum int {
    	OK, 
    	OOB, 
    	Invalid_Capture_Index, 
    	Invalid_Pattern_Capture, 
    	Unfinished_Capture, 
    	Malformed_Pattern, 
    	Rune_Error, 
    	Match_Invalid, 
    }
    Related Procedures With Returns

    Gsub_Proc ¶

    Gsub_Proc :: proc(data: rawptr, word: string, haystack: string, captures: []Match)
    Related Procedures With Parameters

    Match ¶

    Match :: struct {
    	byte_start: int,
    	byte_end:   int,
    }
    Related Procedures With Returns

    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
    Related Procedures With Returns

    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 ¶

    SPECIALS_TABLE: [256]bool = …
     

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

    Procedures

    capture_to_close ¶

    capture_to_close :: proc(ms: ^Match_State) -> (int, Error) {…}

    check_capture ¶

    check_capture :: proc(ms: ^Match_State, l: rune) -> (int, Error) {…}

    class_end ¶

    class_end :: proc(ms: ^Match_State, p: int) -> (step: int, err: Error) {…}

    end_capture ¶

    end_capture :: proc(ms: ^Match_State, s, p: int) -> (res: int, err: Error) {…}

    find_aux ¶

    find_aux :: proc(haystack: string, 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 ¶

    gfind :: proc(haystack: ^string, pattern: string, captures: ^[32]Match) -> (res: string, ok: bool) {…}
     

    iterative find with zeroth capture only

    gmatch ¶

    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

    gsub_allocator ¶

    gsub_allocator :: proc(haystack: string, pattern: string, replace: string, allocator := context.allocator) -> string {…}
     

    uses temp builder to build initial string - then allocates the result

    gsub_builder ¶

    gsub_builder :: proc(builder: ^strings.Builder, haystack: string, pattern: string, replace: string) -> string {…}
     

    gsub with builder, replace patterns found with the replace content

    gsub_with ¶

    gsub_with :: proc(haystack: string, pattern: string, data: rawptr, call: Gsub_Proc) {…}
     

    call a procedure on every match in the haystack

    index_special ¶

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

    helper call to quick search for special characters

    is_alnum ¶

    is_alnum :: proc(c: rune) -> bool {…}

    is_cont ¶

    is_cont :: proc(b: u8) -> bool {…}
     

    continuation byte?

    is_graph ¶

    is_graph :: proc(c: rune) -> bool {…}

    is_xdigit ¶

    is_xdigit :: proc(c: rune) -> bool {…}

    lmem_find ¶

    lmem_find :: proc(s1, s2: string) -> int {…}

    match ¶

    match :: proc(ms: ^Match_State, s, p: int) -> (unused: int, err: Error) {…}

    match_balance ¶

    match_balance :: proc(ms: ^Match_State, s, p: int) -> (unused: int, err: Error) {…}

    match_bracket_class ¶

    match_bracket_class :: proc(ms: ^Match_State, c: rune, p, ec: int) -> (sig: bool, err: Error) {…}

    match_capture ¶

    match_capture :: proc(ms: ^Match_State, s: int, char: rune) -> (res: int, err: Error) {…}

    match_class ¶

    match_class :: proc(c: rune, cl: rune) -> (res: bool) {…}

    match_default ¶

    match_default :: proc(ms: ^Match_State, s, p: int) -> (unused: int, err: Error) {…}

    matcher_capture ¶

    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 ¶

    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 ¶

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

    get a slice of all valid captures above the first match

    matcher_find ¶

    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 ¶

    matcher_gmatch :: matcher_match_iter
     

    iteratively match the haystack till it cant find any matches

    matcher_init ¶

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

    init using haystack & pattern and an optional byte offset

    matcher_match ¶

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

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

    matcher_match_iter ¶

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

    iteratively match the haystack till it cant find any matches

    max_expand ¶

    max_expand :: proc(ms: ^Match_State, s, p, ep: int) -> (res: int, err: Error) {…}

    min_expand ¶

    min_expand :: proc(ms: ^Match_State, s, p, ep: int) -> (res: int, err: Error) {…}

    pattern_case_insensitive_allocator ¶

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

    pattern_case_insensitive_builder ¶

    pattern_case_insensitive_builder :: proc(builder: ^strings.Builder, pattern: string) -> (res: string) {…}
     

    rebuilds a pattern into a case insensitive pattern

    push_captures ¶

    push_captures :: proc(ms: ^Match_State, s: int, e: int, matches: []Match) -> (nlevels: int, err: Error) {…}

    push_onecapture ¶

    push_onecapture :: proc(ms: ^Match_State, i: int, s: int, e: int, matches: []Match) -> (err: Error) {…}

    single_match ¶

    single_match :: proc(ms: ^Match_State, s, p, ep: int) -> (matched: bool, schar_size: int, err: Error) {…}

    start_capture ¶

    start_capture :: proc(ms: ^Match_State, s, p, what: int) -> (res: int, err: Error) {…}

    utf8_advance ¶

    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_next ¶

    utf8_next :: proc(bytes: string, a: int) -> int {…}

    utf8_peek ¶

    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

    utf8_prev ¶

    utf8_prev :: proc(bytes: string, a, b: int) -> int {…}

    Procedure Groups

    Source Files

    Generation Information

    Generated with odin version dev-2024-04 (vendor "odin") Windows_amd64 @ 2024-04-26 21:08:59.118172400 +0000 UTC