2015-12-24 17:54:54 +03:00
|
|
|
package match
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-01-08 20:14:31 +03:00
|
|
|
"strings"
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.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
|
|
|
}
|
|
|
|
|
|
|
|
func (self Single) Index(s string) (int, []int) {
|
|
|
|
for i, r := range s {
|
|
|
|
if strings.IndexRune(self.Separators, r) == -1 {
|
|
|
|
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
|
|
|
}
|