1 package match 2 3 import ( 4 "fmt" 5 "github.com/gobwas/glob/util/runes" 6 "unicode/utf8" 7 ) 8 9 // single represents ? 10 type Single struct { 11 Separators []rune 12 } 13 14 func NewSingle(s []rune) Single { 15 return Single{s} 16 } 17 18 func (self Single) Match(s string) bool { 19 r, w := utf8.DecodeRuneInString(s) 20 if len(s) > w { 21 return false 22 } 23 24 return runes.IndexRune(self.Separators, r) == -1 25 } 26 27 func (self Single) Len() int { 28 return lenOne 29 } 30 31 func (self Single) Index(s string) (int, []int) { 32 for i, r := range s { 33 if runes.IndexRune(self.Separators, r) == -1 { 34 return i, segmentsByRuneLength[utf8.RuneLen(r)] 35 } 36 } 37 38 return -1, nil 39 } 40 41 func (self Single) String() string { 42 return fmt.Sprintf("<single:![%s]>", string(self.Separators)) 43 } 44