glob/match/list.go

42 lines
560 B
Go
Raw Normal View History

2015-12-24 17:54:54 +03:00
package match
import (
"strings"
"fmt"
)
type RangeList struct {
List string
Not bool
}
func (self RangeList) Kind() Kind {
return KindRangeList
}
func (self RangeList) Search(s string) (i int, l int, ok bool) {
if self.Match(s) {
return 0, len(s), true
}
return
}
func (self RangeList) Match(s string) bool {
r := []rune(s)
if (len(r) != 1) {
return false
}
inList := strings.IndexRune(self.List, r[0]) >= 0
return inList == !self.Not
}
func (self RangeList) String() string {
return fmt.Sprintf("[range_list:%s]", self.List)
}