File: matcher.go

package info (click to toggle)
snowflake 2.10.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,104 kB
  • sloc: makefile: 5
file content (31 lines) | stat: -rw-r--r-- 674 bytes parent folder | download | duplicates (2)
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)
}