2015-12-24 17:54:54 +03:00
|
|
|
package match
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-01-09 02:34:41 +03:00
|
|
|
"strings"
|
2015-12-24 17:54:54 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Suffix struct {
|
|
|
|
Suffix string
|
|
|
|
}
|
|
|
|
|
2016-02-02 22:03:37 +03:00
|
|
|
func (self Suffix) Index(s string, segments []int) (int, []int) {
|
2016-01-12 14:06:59 +03:00
|
|
|
idx := strings.Index(s, self.Suffix)
|
|
|
|
if idx == -1 {
|
|
|
|
return -1, nil
|
|
|
|
}
|
|
|
|
|
2016-02-02 22:03:37 +03:00
|
|
|
return 0, append(segments, idx+len(self.Suffix))
|
2016-01-12 14:06:59 +03:00
|
|
|
}
|
|
|
|
|
2016-01-09 02:34:41 +03:00
|
|
|
func (self Suffix) Len() int {
|
2016-01-14 18:29:13 +03:00
|
|
|
return lenNo
|
2016-01-09 02:34:41 +03:00
|
|
|
}
|
|
|
|
|
2015-12-24 17:54:54 +03:00
|
|
|
func (self Suffix) Match(s string) bool {
|
|
|
|
return strings.HasSuffix(s, self.Suffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self Suffix) String() string {
|
2016-01-13 01:26:48 +03:00
|
|
|
return fmt.Sprintf("<suffix:%s>", self.Suffix)
|
2015-12-24 17:54:54 +03:00
|
|
|
}
|