From 1da3f7f0e05a777f4d7b950b95ee7f9e453c945c Mon Sep 17 00:00:00 2001 From: Rockingcool Date: Mon, 6 Jan 2025 20:14:19 -0600 Subject: [PATCH] Changed API for match-finding functions - take in a Reg instead of start state and numGroups separately --- matching.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/matching.go b/matching.go index c4f5665..66043ba 100644 --- a/matching.go +++ b/matching.go @@ -141,13 +141,14 @@ func pruneIndices(indices []Match) []Match { // findNthMatch finds the 'n'th match of the regex represented by the given start-state, with // the given string. // It returns an error (!= nil) if there are fewer than 'n' matches in the string. -func findNthMatch(start *State, str []rune, numGroups int, n int) (Match, error) { +func findNthMatch(regex Reg, str string, n int) (Match, error) { idx := 0 matchNum := 0 + str_runes := []rune(str) var matchFound bool var matchIdx Match - for idx <= len(str) { - matchFound, matchIdx, idx = findAllMatchesHelper(start, str, idx, numGroups) + for idx <= len(str_runes) { + matchFound, matchIdx, idx = findAllMatchesHelper(regex.start, str_runes, idx, regex.numGroups) if matchFound { matchNum++ } @@ -161,13 +162,14 @@ func findNthMatch(start *State, str []rune, numGroups int, n int) (Match, error) // findAllMatches tries to find all matches of the regex represented by given start-state, with // the given string -func findAllMatches(start *State, str []rune, numGroups int) []Match { +func findAllMatches(regex Reg, str string) []Match { idx := 0 + str_runes := []rune(str) var matchFound bool var matchIdx Match indices := make([]Match, 0) - for idx <= len(str) { - matchFound, matchIdx, idx = findAllMatchesHelper(start, str, idx, numGroups) + for idx <= len(str_runes) { + matchFound, matchIdx, idx = findAllMatchesHelper(regex.start, str_runes, idx, regex.numGroups) if matchFound { indices = append(indices, matchIdx) }