Replaced call to 'FindAllMatches' with call to 'FindAll' or 'FindAllSubmatch' depending on whether I need submatches

This commit is contained in:
2025-01-31 09:55:36 -05:00
parent 45b6566b2c
commit 8eda5055ff
2 changed files with 34 additions and 11 deletions

View File

@@ -156,17 +156,18 @@ func (s nfaState) checkAssertion(str []rune, idx int) bool {
strToMatch = string(runesToMatch)
}
matchIndices := FindAllMatches(Reg{startState, s.lookaroundNumCaptureGroups}, strToMatch)
regComp := Reg{startState, s.lookaroundNumCaptureGroups}
matchIndices := regComp.FindAll(strToMatch)
numMatchesFound := 0
for _, matchIdx := range matchIndices {
if s.assert == plaAssert || s.assert == nlaAssert { // Lookahead - return true (or false) if at least one match starts at 0. Zero is used because the test-string _starts_ from idx.
if matchIdx[0].StartIdx == 0 {
if matchIdx.StartIdx == 0 {
numMatchesFound++
}
}
if s.assert == plbAssert || s.assert == nlbAssert { // Lookbehind - return true (or false) if at least one match _ends_ at the current index.
if matchIdx[0].EndIdx == idx {
if matchIdx.EndIdx == idx {
numMatchesFound++
}
}