1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
package namematcher
import "strings"
func NewNameMatcher(rule string) NameMatcher {
rule = strings.TrimSuffix(rule, "$")
return NameMatcher{suffix: strings.TrimPrefix(rule, "^"), exact: strings.HasPrefix(rule, "^")}
}
func IsValidRule(rule string) bool {
return strings.HasSuffix(rule, "$")
}
type NameMatcher struct {
exact bool
suffix string
}
func (m *NameMatcher) IsSupersetOf(matcher NameMatcher) bool {
if m.exact {
return matcher.exact && m.suffix == matcher.suffix
}
return strings.HasSuffix(matcher.suffix, m.suffix)
}
func (m *NameMatcher) IsMember(s string) bool {
if m.exact {
return s == m.suffix
}
return strings.HasSuffix(s, m.suffix)
}
|