Changed API for match-finding functions - take in a Reg instead of start state and numGroups separately

master
Aadhavan Srinivasan 2 weeks ago
parent 8e8067482a
commit 1da3f7f0e0

@ -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)
}

Loading…
Cancel
Save