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