glob/match/prefix.go

33 lines
437 B
Go
Raw Normal View History

2015-12-24 17:54:54 +03:00
package match
import (
"strings"
"fmt"
)
type Prefix struct {
Prefix string
}
func (self Prefix) Kind() Kind {
return KindPrefix
}
func (self Prefix) Search(s string) (i int, l int, ok bool) {
if self.Match(s) {
return 0, len(s), true
}
return
}
func (self Prefix) Match(s string) bool {
return strings.HasPrefix(s, self.Prefix)
}
func (self Prefix) String() string {
return fmt.Sprintf("[prefix:%s]", self.Prefix)
}