glob/match/single.go

40 lines
643 B
Go
Raw Normal View History

2015-12-24 17:54:54 +03:00
package match
import (
"fmt"
2016-02-02 22:03:37 +03:00
"github.com/gobwas/glob/runes"
2016-01-09 02:34:41 +03:00
"unicode/utf8"
2015-12-24 17:54:54 +03:00
)
// single represents ?
type Single struct {
2016-02-02 14:57:42 +03:00
Separators []rune
2015-12-24 17:54:54 +03:00
}
func (self Single) Match(s string) bool {
2016-01-15 19:50:12 +03:00
r, w := utf8.DecodeRuneInString(s)
if len(s) > w {
return false
}
2016-02-02 22:03:37 +03:00
return runes.IndexRune(self.Separators, r) == -1
2015-12-24 17:54:54 +03:00
}
2016-01-09 02:34:41 +03:00
func (self Single) Len() int {
2016-01-14 18:29:13 +03:00
return lenOne
2016-01-09 02:34:41 +03:00
}
2016-02-05 17:29:41 +03:00
func (self Single) Index(s string) (int, []int) {
2016-01-09 02:34:41 +03:00
for i, r := range s {
2016-02-02 22:03:37 +03:00
if runes.IndexRune(self.Separators, r) == -1 {
2016-02-05 17:29:41 +03:00
return i, []int{utf8.RuneLen(r)}
2016-01-08 20:14:31 +03:00
}
2015-12-24 17:54:54 +03:00
}
2016-01-09 02:34:41 +03:00
return -1, nil
2015-12-24 17:54:54 +03:00
}
func (self Single) String() string {
2016-01-13 01:26:48 +03:00
return fmt.Sprintf("<single:![%s]>", self.Separators)
2015-12-24 17:54:54 +03:00
}