mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
31 lines
674 B
Go
31 lines
674 B
Go
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)
|
|
}
|