glob/match/every_of.go

45 lines
606 B
Go
Raw Normal View History

2016-01-08 20:14:31 +03:00
package match
import (
"fmt"
)
type Every struct {
Matchers Matchers
}
2016-01-09 02:34:41 +03:00
func (self *Every) Add(m Matcher) error {
2016-01-08 20:14:31 +03:00
self.Matchers = append(self.Matchers, m)
2016-01-09 02:34:41 +03:00
return nil
}
func (self Every) Len() (l int) {
for _, m := range self.Matchers {
if ml := m.Len(); l > 0 {
l += ml
} else {
return -1
}
}
return
2016-01-08 20:14:31 +03:00
}
func (self Every) Match(s string) bool {
for _, m := range self.Matchers {
if !m.Match(s) {
return false
}
}
return true
}
func (self Every) Kind() Kind {
return KindEveryOf
}
func (self Every) String() string {
return fmt.Sprintf("[every_of:%s]", self.Matchers)
}