glob/match/prefix_suffix.go

35 lines
590 B
Go
Raw Normal View History

2015-12-24 17:54:54 +03:00
package match
import (
"fmt"
2016-01-08 20:14:31 +03:00
"strings"
2015-12-24 17:54:54 +03:00
)
type PrefixSuffix struct {
Prefix, Suffix string
}
2016-01-08 20:14:31 +03:00
func (self PrefixSuffix) Kind() Kind {
2015-12-24 17:54:54 +03:00
return KindPrefixSuffix
}
2016-01-09 02:34:41 +03:00
func (self PrefixSuffix) Len() int {
return -1
}
2016-01-08 20:14:31 +03:00
func (self PrefixSuffix) Search(s string) (i int, l int, ok bool) {
2015-12-24 17:54:54 +03:00
if self.Match(s) {
return 0, len(s), true
}
return
}
func (self PrefixSuffix) Match(s string) bool {
return strings.HasPrefix(s, self.Prefix) && strings.HasSuffix(s, self.Suffix)
}
func (self PrefixSuffix) String() string {
return fmt.Sprintf("[prefix_suffix:%s-%s]", self.Prefix, self.Suffix)
2016-01-08 20:14:31 +03:00
}