Unique append to match indices (ensure match indices aren't repeated

master
Aadhavan Srinivasan 2 months ago
parent 704bec122a
commit df6efcd1f0

@ -33,7 +33,7 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset
if len(str) == 0 { if len(str) == 0 {
// If the start is a Kleene star, then it should also match an empty string. // If the start is a Kleene star, then it should also match an empty string.
if start.isKleene && start.isLast { if start.isKleene && start.isLast {
indices = append(indices, matchIndex{offset, offset}) indices, _ = unique_append(indices, matchIndex{offset, offset})
} }
return indices return indices
} }
@ -90,7 +90,7 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset
for _, state := range currentStates { for _, state := range currentStates {
if state.isLast { if state.isLast {
endIdx = i endIdx = i
indices = append(indices, matchIndex{startIdx + offset, endIdx + offset}) indices, _ = unique_append(indices, matchIndex{startIdx + offset, endIdx + offset})
} }
} }
// Recursion - match with rest of string if we have nowhere to go. If we haven't moved in the string, increment the counter by 1 to ensure we don't keep trying the same string over and over // Recursion - match with rest of string if we have nowhere to go. If we haven't moved in the string, increment the counter by 1 to ensure we don't keep trying the same string over and over
@ -126,7 +126,7 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset
// Only add the match if we the start index is in bounds // Only add the match if we the start index is in bounds
if state.isLast && startIdx+offset < len(str)+offset { if state.isLast && startIdx+offset < len(str)+offset {
endIdx = i endIdx = i
indices = append(indices, matchIndex{startIdx + offset, endIdx + offset}) indices, _ = unique_append(indices, matchIndex{startIdx + offset, endIdx + offset})
} }
} }

Loading…
Cancel
Save