glob/match/any.go

47 lines
717 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
2016-01-18 13:07:28 +03:00
case 0:
return 0, []int{0}
2016-01-12 14:06:59 +03:00
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 {
2016-01-14 18:29:13 +03:00
return lenNo
2016-01-09 02:34:41 +03:00
}
2016-01-08 20:14:31 +03:00
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
}