mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
617 B
37 lines
617 B
package strmatcher
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
type fullMatcher string
|
|
|
|
func (m fullMatcher) Match(s string) bool {
|
|
return string(m) == s
|
|
}
|
|
|
|
type substrMatcher string
|
|
|
|
func (m substrMatcher) Match(s string) bool {
|
|
return strings.Contains(s, string(m))
|
|
}
|
|
|
|
type domainMatcher string
|
|
|
|
func (m domainMatcher) Match(s string) bool {
|
|
pattern := string(m)
|
|
if !strings.HasSuffix(s, pattern) {
|
|
return false
|
|
}
|
|
return len(s) == len(pattern) || s[len(s)-len(pattern)-1] == '.'
|
|
}
|
|
|
|
type regexMatcher struct {
|
|
pattern *regexp.Regexp
|
|
}
|
|
|
|
func (m *regexMatcher) Match(s string) bool {
|
|
return m.pattern.MatchString(s)
|
|
}
|