glob/match/any.go

47 lines
681 B
Go
Raw Normal View History

2016-01-08 20:14:31 +03:00
package match
import (
"fmt"
2018-02-16 17:36:02 +03:00
"github.com/gobwas/glob/util/runes"
2016-01-08 20:14:31 +03:00
)
type Any struct {
2018-02-16 17:36:02 +03:00
sep []rune
2016-01-08 20:14:31 +03:00
}
func NewAny(s []rune) Any {
return Any{s}
}
2018-02-16 17:36:02 +03:00
func (a Any) Match(s string) bool {
return runes.IndexAnyRune(s, a.sep) == -1
2016-01-08 20:14:31 +03:00
}
2018-02-16 17:36:02 +03:00
func (a Any) Index(s string) (int, []int) {
found := runes.IndexAnyRune(s, a.sep)
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
}
2018-02-16 17:36:02 +03:00
func (a Any) MinLen() int {
return 0
2016-01-09 02:34:41 +03:00
}
2018-02-16 17:36:02 +03:00
func (a Any) String() string {
return fmt.Sprintf("<any:![%s]>", string(a.sep))
2016-01-08 20:14:31 +03:00
}