1package match
2
3import (
4	"fmt"
5	"unicode/utf8"
6)
7
8type Min struct {
9	Limit int
10}
11
12func NewMin(l int) Min {
13	return Min{l}
14}
15
16func (self Min) Match(s string) bool {
17	var l int
18	for range s {
19		l += 1
20		if l >= self.Limit {
21			return true
22		}
23	}
24
25	return false
26}
27
28func (self Min) Index(s string) (int, []int) {
29	var count int
30
31	c := len(s) - self.Limit + 1
32	if c <= 0 {
33		return -1, nil
34	}
35
36	segments := acquireSegments(c)
37	for i, r := range s {
38		count++
39		if count >= self.Limit {
40			segments = append(segments, i+utf8.RuneLen(r))
41		}
42	}
43
44	if len(segments) == 0 {
45		return -1, nil
46	}
47
48	return 0, segments
49}
50
51func (self Min) Len() int {
52	return lenNo
53}
54
55func (self Min) String() string {
56	return fmt.Sprintf("<min:%d>", self.Limit)
57}
58