From df6efcd1f00d49d58d64839c858df9d7e818240d Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 28 Oct 2024 15:44:37 -0400 Subject: [PATCH] Unique append to match indices (ensure match indices aren't repeated --- matching.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matching.go b/matching.go index 613d005..000c88c 100644 --- a/matching.go +++ b/matching.go @@ -33,7 +33,7 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset if len(str) == 0 { // If the start is a Kleene star, then it should also match an empty string. if start.isKleene && start.isLast { - indices = append(indices, matchIndex{offset, offset}) + indices, _ = unique_append(indices, matchIndex{offset, offset}) } return indices } @@ -90,7 +90,7 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset for _, state := range currentStates { if state.isLast { 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 @@ -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 if state.isLast && startIdx+offset < len(str)+offset { endIdx = i - indices = append(indices, matchIndex{startIdx + offset, endIdx + offset}) + indices, _ = unique_append(indices, matchIndex{startIdx + offset, endIdx + offset}) } }