refactored newPattern()

master
Charles Iliya Krempeaux 2019-06-20 23:37:46 -07:00
parent 83fa66ddd9
commit fbedc7e73f
2 changed files with 14 additions and 11 deletions

View File

@ -35,7 +35,9 @@ var (
// } // }
func Compile(uncompiledPattern string) (*Pattern, error) { func Compile(uncompiledPattern string) (*Pattern, error) {
pattern := newPattern(defaultFieldTagName) var pattern Pattern
newPattern(&pattern, defaultFieldTagName)
s := uncompiledPattern s := uncompiledPattern
for { for {
@ -92,7 +94,7 @@ func Compile(uncompiledPattern string) (*Pattern, error) {
} }
return pattern, nil return &pattern, nil
} }

View File

@ -37,20 +37,21 @@ type Pattern struct {
fieldTagName string fieldTagName string
} }
func newPattern(fieldTagName string) *Pattern { func newPattern(target *Pattern, fieldTagName string) error {
if nil == target {
return errNilTarget
}
bits := []string{} bits := []string{}
names := []string{} names := []string{}
namesSet := map[string]struct{}{} namesSet := map[string]struct{}{}
pattern := Pattern{ target.bits = bits
bits:bits, target.names = names
names:names, target.namesSet = namesSet
namesSet:namesSet, target.fieldTagName = fieldTagName
fieldTagName:fieldTagName,
}
return &pattern
return nil
} }
func (pattern *Pattern) MatchNames() []string { func (pattern *Pattern) MatchNames() []string {