From c894ee4c0de2119e523d1fd63d54551af57fafee Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Thu, 24 Oct 2024 12:31:37 -0400 Subject: [PATCH] Renamed match function to 'findAllMatches', to better represent what it does --- main.go | 2 +- matching.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 66daf99..968dbee 100644 --- a/main.go +++ b/main.go @@ -178,7 +178,7 @@ func main() { re_postfix := shuntingYard(re) // fmt.Println(re_postfix) startState := thompson(re_postfix) - matchIndices := match(startState, os.Args[2]) + matchIndices := findAllMatches(startState, os.Args[2]) inColor := false if len(matchIndices) > 0 { for i, c := range os.Args[2] { diff --git a/matching.go b/matching.go index 63c206a..6904cf5 100644 --- a/matching.go +++ b/matching.go @@ -23,12 +23,12 @@ func takeZeroState(states []*State) (rtv []*State, isZero bool) { return rtv, false } -// match tries to match the regex represented by given start-state, with +// findAllMatches tries to findAllMatches the regex represented by given start-state, with // the given string -func match(start *State, str string) (indices []matchIndex) { - return matchHelper(start, str, make([]matchIndex, 0), 0) +func findAllMatches(start *State, str string) (indices []matchIndex) { + return findAllMatchesHelper(start, str, make([]matchIndex, 0), 0) } -func matchHelper(start *State, str string, indices []matchIndex, offset int) []matchIndex { +func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset int) []matchIndex { // 'Base case' - exit if string is empty if len(str) == 0 { return indices @@ -86,7 +86,7 @@ func matchHelper(start *State, str string, indices []matchIndex, offset int) []m if i == startingFrom { i++ } - return matchHelper(start, str[i:], indices, offset+i) + return findAllMatchesHelper(start, str[i:], indices, offset+i) } currentStates = make([]*State, len(tempStates)) copy(currentStates, tempStates)