glob/match/any.go

49 lines
733 B
Go
Raw Normal View History

2016-01-08 20:14:31 +03:00
package match
import (
"fmt"
"strings"
2016-01-12 14:06:59 +03:00
"unicode/utf8"
2016-01-08 20:14:31 +03:00
)
type Any struct {
Separators string
}
func (self Any) Match(s string) bool {
return strings.IndexAny(s, self.Separators) == -1
}
2016-01-12 14:06:59 +03:00
func (self Any) Index(s string) (int, []int) {
var sub string
found := strings.IndexAny(s, self.Separators)
switch found {
case -1:
sub = s
default:
sub = s[:found]
}
segments := make([]int, 0, utf8.RuneCountInString(sub)+1)
for i := range sub {
segments = append(segments, i)
2016-01-08 20:14:31 +03:00
}
2016-01-12 14:06:59 +03:00
segments = append(segments, len(sub))
return 0, segments
2016-01-08 20:14:31 +03:00
}
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 {
2016-01-13 01:26:48 +03:00
return fmt.Sprintf("<any:![%s]>", self.Separators)
2016-01-08 20:14:31 +03:00
}