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) {
pattern := newPattern(defaultFieldTagName)
var pattern Pattern
newPattern(&pattern, defaultFieldTagName)
s := uncompiledPattern
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
}
func newPattern(fieldTagName string) *Pattern {
func newPattern(target *Pattern, fieldTagName string) error {
if nil == target {
return errNilTarget
}
bits := []string{}
names := []string{}
namesSet := map[string]struct{}{}
pattern := Pattern{
bits:bits,
names:names,
namesSet:namesSet,
fieldTagName:fieldTagName,
}
return &pattern
target.bits = bits
target.names = names
target.namesSet = namesSet
target.fieldTagName = fieldTagName
return nil
}
func (pattern *Pattern) MatchNames() []string {