glob/match/any.go

42 lines
687 B
Go
Raw Normal View History

2016-01-08 20:14:31 +03:00
package match
import (
"fmt"
2016-02-02 22:03:37 +03:00
"github.com/gobwas/glob/strings"
2016-01-08 20:14:31 +03:00
)
type Any struct {
2016-02-02 14:57:42 +03:00
Separators []rune
2016-01-08 20:14:31 +03:00
}
func (self Any) Match(s string) bool {
2016-02-02 22:03:37 +03:00
return strings.IndexAnyRunes(s, self.Separators) == -1
2016-01-08 20:14:31 +03:00
}
2016-02-05 17:29:41 +03:00
func (self Any) Index(s string) (int, []int) {
2016-02-02 22:03:37 +03:00
found := strings.IndexAnyRunes(s, self.Separators)
2016-01-12 14:06:59 +03:00
switch found {
case -1:
2016-01-18 13:07:28 +03:00
case 0:
2016-02-23 14:46:20 +03:00
return 0, segments0
2016-01-12 14:06:59 +03:00
default:
2016-02-02 22:03:37 +03:00
s = s[:found]
2016-01-12 14:06:59 +03:00
}
2016-02-22 23:47:31 +03:00
segments := acquireSegments(len(s))
2016-02-02 22:03:37 +03:00
for i := range s {
2016-01-12 14:06:59 +03:00
segments = append(segments, i)
2016-01-08 20:14:31 +03:00
}
2016-02-02 22:03:37 +03:00
segments = append(segments, len(s))
2016-01-12 14:06:59 +03:00
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-02-24 11:19:54 +03:00
return fmt.Sprintf("<any:![%s]>", string(self.Separators))
2016-01-08 20:14:31 +03:00
}