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 {
|
|
|
|
Separators string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self Single) Match(s string) bool {
|
2016-01-09 02:34:41 +03:00
|
|
|
return utf8.RuneCountInString(s) == 1 && strings.IndexAny(s, self.Separators) == -1
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|
|
|
|
|
2016-01-09 02:34:41 +03:00
|
|
|
func (self Single) Len() int {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
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) Kind() Kind {
|
|
|
|
return KindSingle
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|