2015-12-24 17:54:54 +03:00
|
|
|
package match
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-01-08 20:14:31 +03:00
|
|
|
"strings"
|
2015-12-24 17:54:54 +03:00
|
|
|
)
|
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
type List struct {
|
2015-12-24 17:54:54 +03:00
|
|
|
List string
|
|
|
|
Not bool
|
|
|
|
}
|
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
func (self List) Kind() Kind {
|
|
|
|
return KindList
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
func (self List) Match(s string) bool {
|
|
|
|
if len([]rune(s)) != 1 {
|
|
|
|
return false
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
inList := strings.Index(self.List, s) != -1
|
2015-12-24 17:54:54 +03:00
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
return inList == !self.Not
|
|
|
|
}
|
2015-12-24 17:54:54 +03:00
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
func (self List) Index(s string) (index, min, max int) {
|
|
|
|
for i, r := range []rune(s) {
|
|
|
|
if self.Not == (strings.IndexRune(self.List, r) == -1) {
|
|
|
|
return i, 1, 1
|
|
|
|
}
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
return -1, 0, 0
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
func (self List) String() string {
|
|
|
|
return fmt.Sprintf("[list:list=%s not=%t]", self.List, self.Not)
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|