refactored newPattern()
parent
83fa66ddd9
commit
fbedc7e73f
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
19
pattern.go
19
pattern.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue