mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
52 lines
963 B
Go
52 lines
963 B
Go
package geodata
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/Dreamacro/clash/rule/geodata/router"
|
|
)
|
|
|
|
type AttributeList struct {
|
|
matcher []AttributeMatcher
|
|
}
|
|
|
|
func (al *AttributeList) Match(domain *router.Domain) bool {
|
|
for _, matcher := range al.matcher {
|
|
if !matcher.Match(domain) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (al *AttributeList) IsEmpty() bool {
|
|
return len(al.matcher) == 0
|
|
}
|
|
|
|
func parseAttrs(attrs []string) *AttributeList {
|
|
al := new(AttributeList)
|
|
for _, attr := range attrs {
|
|
trimmedAttr := strings.ToLower(strings.TrimSpace(attr))
|
|
if len(trimmedAttr) == 0 {
|
|
continue
|
|
}
|
|
al.matcher = append(al.matcher, BooleanMatcher(trimmedAttr))
|
|
}
|
|
return al
|
|
}
|
|
|
|
type AttributeMatcher interface {
|
|
Match(*router.Domain) bool
|
|
}
|
|
|
|
type BooleanMatcher string
|
|
|
|
func (m BooleanMatcher) Match(domain *router.Domain) bool {
|
|
for _, attr := range domain.Attribute {
|
|
if strings.EqualFold(attr.GetKey(), string(m)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|