matchergroup_simple.go 885 B

123456789101112131415161718192021222324252627282930313233343536
  1. package strmatcher
  2. type matcherEntry struct {
  3. matcher Matcher
  4. value uint32
  5. }
  6. // SimpleMatcherGroup is an implementation of MatcherGroup.
  7. // It simply stores all matchers in an array and sequentially matches them.
  8. type SimpleMatcherGroup struct {
  9. matchers []matcherEntry
  10. }
  11. // AddMatcher implements MatcherGroupForAll.AddMatcher.
  12. func (g *SimpleMatcherGroup) AddMatcher(matcher Matcher, value uint32) {
  13. g.matchers = append(g.matchers, matcherEntry{
  14. matcher: matcher,
  15. value: value,
  16. })
  17. }
  18. // Match implements MatcherGroup.Match.
  19. func (g *SimpleMatcherGroup) Match(input string) []uint32 {
  20. result := []uint32{}
  21. for _, e := range g.matchers {
  22. if e.matcher.Match(input) {
  23. result = append(result, e.value)
  24. }
  25. }
  26. return result
  27. }
  28. // MatchAny implements MatcherGroup.MatchAny.
  29. func (g *SimpleMatcherGroup) MatchAny(input string) bool {
  30. return len(g.Match(input)) > 0
  31. }