Renamed 'FindAllMatches' to 'FindAll' and made it a method; made it return a slice of 0-groups; the functionality of 'FindAllMatches' is now in 'FindAllSubmatch'

master
Aadhavan Srinivasan 2 days ago
parent 692de2a32b
commit e22822e619

@ -153,8 +153,9 @@ func (regex Reg) FindString(str string) string {
// FindAllString is the 'all' version of FindString. // FindAllString is the 'all' version of FindString.
// It returns a slice of strings containing the text of all matches of // It returns a slice of strings containing the text of all matches of
// the regex in the given string. // the regex in the given string.
func FindAllString(regex Reg, str []string) []string { func (regex Reg) FindAllString(str string) []string {
return []string{} return []string{}
// matches := FindAllMatches, str string)
} }
// FindNthMatch finds the 'n'th match of the regex represented by the given start-state, with // FindNthMatch finds the 'n'th match of the regex represented by the given start-state, with
@ -179,9 +180,18 @@ func FindNthMatch(regex Reg, str string, n int) (Match, error) {
return nil, fmt.Errorf("invalid match index - too few matches found") return nil, fmt.Errorf("invalid match index - too few matches found")
} }
// FindAllMatches tries to find all matches of the regex represented by given start-state, with // FindAll returns a slice containing all the 0-groups of the regex in the given string.
// the given string // A 0-group represents the match without any submatches.
func FindAllMatches(regex Reg, str string) []Match { func (regex Reg) FindAll(str string) []Group {
indices := regex.FindAllSubmatch(str)
zeroGroups := funcMap(indices, func(m Match) Group {
return m[0]
})
return zeroGroups
}
// FindAllSubmatch returns a slice of matches in the given string.
func (regex Reg) FindAllSubmatch(str string) []Match {
idx := 0 idx := 0
str_runes := []rune(str) str_runes := []rune(str)
var matchFound bool var matchFound bool
@ -196,6 +206,7 @@ func FindAllMatches(regex Reg, str string) []Match {
if len(indices) > 0 { if len(indices) > 0 {
return pruneIndices(indices) return pruneIndices(indices)
} }
return indices return indices
} }

Loading…
Cancel
Save