// BeforeMatcher inserts the matched elements before each element in the set of matched elements.
//
// This follows the same rules as Selection.Append.
549905
func (s *Selection) BeforeMatcher(m Matcher) *Selection {
	return s.BeforeNodes(m.MatchAll(s.document.rootNode)...)
}
1141200
func (s *Selection) ClosestMatcher(m Matcher) *Selection {
	return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node {
		// For each node in the selection, test the node itself, then each parent
		// until a match is found.
		for ; n != nil; n = n.Parent {
			if m.Match(n) {
				return []*html.Node{n}
			}
		}
		return nil
	}))
}
903702
func NewMatcher(stack []MatchAttribute) Matcher {
	m := &matcher{stack: stack}
	m.init()

	return m
}
98363
func (s *Selection) NextUntilMatcher(m Matcher) *Selection {
	return pushStack(s, getSiblingNodes(s.Nodes, siblingNextUntil,
		m, nil))
}
135862
func (r *Response) Before(fn func()) {
	r.beforeFuncs = append(r.beforeFuncs, fn)
}
605009
func (s *Selection) FindMatcher(m Matcher) *Selection {
	return pushStack(s, findWithMatcher(s.Nodes, m))
}
669380
func MultiMatcher(m ...Matcher) Matcher {
	fn := func(r *Request) bool {
		for _, matcher := range m {
			if !matcher.Match(r) {
				return false
			}
		}

		return true
	}

	return &MatcherFunc{fn}
}
190534
func DomainMatcher(pattern string) Matcher {
	p := pattern
	if strings.HasPrefix(pattern, ".") {
		p = pattern[1:] // trim the prefix '.'
		pattern = "*" + p
	}
	return &domainMatcher{
		pattern: p,
		glob:    glob.MustCompile(pattern),
	}
}
509360
func BeforeCall(fn func(context.Context, proto.Message) error) Option {
	return func(opts *options) {
		opts.before = fn
	}
}
251957
func (s *Selection) AddMatcher(m Matcher) *Selection {
	return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...)
}
398910
func BeforeStart(fn func() error) Option {
	return func(o *Options) {
		o.BeforeStart = append(o.BeforeStart, fn)
	}
}
1129585
func matcher(label labels.Selector, field fields.Selector) storage.SelectionPredicate {
	return storage.SelectionPredicate{
		Label:    label,
		Field:    field,
		GetAttrs: storage.DefaultClusterScopedAttr,
	}
}
1028343
func Contains(x interface{}) Matcher {
	var result containsMatcher
	var ok bool

	if result.elementMatcher, ok = x.(Matcher); !ok {
		result.elementMatcher = Equals(x)
	}

	return &result
}
821683
func (s *Selection) NextAllMatcher(m Matcher) *Selection {
	return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextAll, nil, nil), m)
}
499277
func (s *Selection) Prepend(selector string) *Selection {
	return s.PrependMatcher(compileMatcher(selector))
}
784345
func (s *Selection) NotMatcher(m Matcher) *Selection {
	return pushStack(s, winnow(s, m, false))
}
1282296
func AddMatcher(fileType types.Type, matcher matchers.Matcher) matchers.TypeMatcher {
	return matchers.NewMatcher(fileType, matcher)
}