2016-01-08 20:14:31 +03:00
|
|
|
package match
|
|
|
|
|
2016-01-09 02:34:41 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"unicode/utf8"
|
|
|
|
)
|
2016-01-08 20:14:31 +03:00
|
|
|
|
|
|
|
type Min struct {
|
|
|
|
Limit int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self Min) Match(s string) bool {
|
2016-01-14 18:29:13 +03:00
|
|
|
var l int
|
|
|
|
for range s {
|
|
|
|
l += 1
|
|
|
|
if l >= self.Limit {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
2016-01-09 02:34:41 +03:00
|
|
|
}
|
|
|
|
|
2016-01-12 14:06:59 +03:00
|
|
|
func (self Min) Index(s string) (int, []int) {
|
|
|
|
var count int
|
|
|
|
|
|
|
|
c := utf8.RuneCountInString(s)
|
|
|
|
if c < self.Limit {
|
|
|
|
return -1, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
segments := make([]int, 0, c-self.Limit+1)
|
|
|
|
for i, r := range s {
|
|
|
|
count++
|
|
|
|
if count >= self.Limit {
|
|
|
|
segments = append(segments, i+utf8.RuneLen(r))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0, segments
|
|
|
|
}
|
|
|
|
|
2016-01-09 02:34:41 +03:00
|
|
|
func (self Min) Len() int {
|
2016-01-14 18:29:13 +03:00
|
|
|
return lenNo
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self Min) Search(s string) (int, int, bool) {
|
|
|
|
return 0, 0, false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self Min) Kind() Kind {
|
|
|
|
return KindMin
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self Min) String() string {
|
2016-01-13 01:26:48 +03:00
|
|
|
return fmt.Sprintf("<min:%d>", self.Limit)
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|