glob/match/any_of.go

58 lines
740 B
Go
Raw Normal View History

2016-01-08 20:14:31 +03:00
package match
import (
"fmt"
)
type AnyOf struct {
Matchers Matchers
}
2016-01-09 02:34:41 +03:00
func (self *AnyOf) 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
2016-01-08 20:14:31 +03:00
}
func (self AnyOf) Match(s string) bool {
for _, m := range self.Matchers {
if m.Match(s) {
return true
}
}
return false
}
2016-01-11 10:17:19 +03:00
//func (self AnyOf) Index(s string) (index int, segments []int) {
//
//}
func (self AnyOf) Len() (l int) {
l = -1
for _, m := range self.Matchers {
ml := m.Len()
if ml == -1 {
return -1
}
if l == -1 {
l = ml
continue
}
if l != ml {
return -1
}
}
return
2016-01-09 02:34:41 +03:00
}
2016-01-08 20:14:31 +03:00
func (self AnyOf) Kind() Kind {
return KindAnyOf
}
func (self AnyOf) String() string {
return fmt.Sprintf("[any_of:%s]", self.Matchers)
}