glob/match/any.go

43 lines
635 B
Go
Raw Normal View History

2016-01-08 20:14:31 +03:00
package match
import (
"fmt"
"strings"
)
type Any struct {
Separators string
}
func (self Any) Match(s string) bool {
return strings.IndexAny(s, self.Separators) == -1
}
2016-01-09 02:34:41 +03:00
func (self Any) Index(s string) (index int, segments []int) {
2016-01-08 20:14:31 +03:00
index = -1
2016-01-09 02:34:41 +03:00
for i, r := range s {
2016-01-08 20:14:31 +03:00
if strings.IndexRune(self.Separators, r) == -1 {
if index == -1 {
index = i
}
2016-01-09 02:34:41 +03:00
segments = append(segments, i-index)
} else if index != -1 {
2016-01-08 20:14:31 +03:00
break
}
}
return
}
2016-01-09 02:34:41 +03:00
func (self Any) Len() int {
return -1
}
2016-01-08 20:14:31 +03:00
func (self Any) Kind() Kind {
return KindAny
}
func (self Any) String() string {
return fmt.Sprintf("[any:%s]", self.Separators)
}