2015-12-24 17:54:54 +03:00
|
|
|
package match
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-01-09 02:34:41 +03:00
|
|
|
"unicode/utf8"
|
2022-12-12 17:24:35 +03:00
|
|
|
|
|
|
|
"git.internal/re/glob/util/runes"
|
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
|
|
|
}
|
|
|
|
|
2016-02-24 12:36:15 +03:00
|
|
|
func NewSingle(s []rune) Single {
|
|
|
|
return Single{s}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-02-02 22:03:37 +03:00
|
|
|
return runes.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
|
|
|
}
|
|
|
|
|
2016-02-05 17:29:41 +03:00
|
|
|
func (self Single) Index(s string) (int, []int) {
|
2016-01-09 02:34:41 +03:00
|
|
|
for i, r := range s {
|
2016-02-02 22:03:37 +03:00
|
|
|
if runes.IndexRune(self.Separators, r) == -1 {
|
2016-02-23 14:46:20 +03:00
|
|
|
return i, segmentsByRuneLength[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-02-24 12:36:15 +03:00
|
|
|
return fmt.Sprintf("<single:![%s]>", string(self.Separators))
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|