2016-01-08 20:14:31 +03:00
|
|
|
package match
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-02-02 22:03:37 +03:00
|
|
|
"github.com/gobwas/glob/strings"
|
2016-01-08 20:14:31 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Any struct {
|
2016-02-02 14:57:42 +03:00
|
|
|
Separators []rune
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self Any) Match(s string) bool {
|
2016-02-02 22:03:37 +03:00
|
|
|
return strings.IndexAnyRunes(s, self.Separators) == -1
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|
|
|
|
|
2016-02-02 22:03:37 +03:00
|
|
|
func (self Any) Index(s string, segments []int) (int, []int) {
|
|
|
|
found := strings.IndexAnyRunes(s, self.Separators)
|
2016-01-12 14:06:59 +03:00
|
|
|
switch found {
|
|
|
|
case -1:
|
2016-01-18 13:07:28 +03:00
|
|
|
case 0:
|
2016-02-02 22:03:37 +03:00
|
|
|
segments = append(segments)
|
|
|
|
return 0, segments
|
2016-01-12 14:06:59 +03:00
|
|
|
default:
|
2016-02-02 22:03:37 +03:00
|
|
|
s = s[:found]
|
2016-01-12 14:06:59 +03:00
|
|
|
}
|
|
|
|
|
2016-02-02 22:03:37 +03:00
|
|
|
for i := range s {
|
2016-01-12 14:06:59 +03:00
|
|
|
segments = append(segments, i)
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|
|
|
|
|
2016-02-02 22:03:37 +03:00
|
|
|
segments = append(segments, len(s))
|
2016-01-12 14:06:59 +03:00
|
|
|
|
|
|
|
return 0, segments
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|
|
|
|
|
2016-01-09 02:34:41 +03:00
|
|
|
func (self Any) Len() int {
|
2016-01-14 18:29:13 +03:00
|
|
|
return lenNo
|
2016-01-09 02:34:41 +03:00
|
|
|
}
|
|
|
|
|
2016-01-08 20:14:31 +03:00
|
|
|
func (self Any) String() string {
|
2016-01-13 01:26:48 +03:00
|
|
|
return fmt.Sprintf("<any:![%s]>", self.Separators)
|
2016-01-08 20:14:31 +03:00
|
|
|
}
|