matchergroup_simple.go 951 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. for _, e := range g.matchers {
  31. if e.matcher.Match(input) {
  32. return true
  33. }
  34. }
  35. return false
  36. }