// match performs the recursive matching for 'any' patterns. An 'any'
// token '**' may match any path component, or no path component.
975878
func (a *any) match(path []string, tokens []*Token) bool {
	// if we have no more tokens, then we have matched this path
	// if there are also no more path elements, otherwise there's no match
	if len(tokens) == 0 {
		return len(path) == 0
	}

	// what token are we trying to match?
	_token := tokens[0]
	switch _token.Type {
	case ANY:
		if len(path) == 0 {
			return a.match(path, tokens[1:])
		} else {
			return a.match(path, tokens[1:]) || a.match(path[1:], tokens)
		}

	default:
		// if we have a non-ANY token, then we must have a non-empty path
		if len(path) != 0 {
			// if the current path element matches this token,
			// we match if the remainder of the path matches the
			// remaining tokens
			if fnmatch.Match(_token.Token(), path[0], fnmatch.FNM_PATHNAME) {
				return a.match(path[1:], tokens[1:])
			}
		}
	}

	// if we are here, then we have no match
	return false
}
1025368
func (s *Intention) Match(
	args *structs.IntentionQueryRequest,
	reply *structs.IndexedIntentionMatches) error {
	// Forward if necessary
	if done, err := s.srv.forward("Intention.Match", args, args, reply); done {
		return err
	}

	// Get the ACL token for the request for the checks below.
	rule, err := s.srv.ResolveToken(args.Token)
	if err != nil {
		return err
	}

	if rule != nil {
		// We go through each entry and test the destination to check if it
		// matches.
		for _, entry := range args.Match.Entries {
			if prefix := entry.Name; prefix != "" && !rule.IntentionRead(prefix) {
				s.srv.logger.Printf("[WARN] consul.intention: Operation on intention prefix '%s' denied due to ACLs", prefix)
				return acl.ErrPermissionDenied
			}
		}
	}

	return s.srv.blockingQuery(
		&args.QueryOptions,
		&reply.QueryMeta,
		func(ws memdb.WatchSet, state *state.Store) error {
			index, matches, err := state.IntentionMatch(ws, args.Match)
			if err != nil {
				return err
			}

			reply.Index = index
			reply.Matches = matches
			return nil
		},
	)
}
715964
func (t *docMatchTree) matches(cp *contentProvider, cost int, known map[matchTree]bool) (bool, bool) {
	return len(t.current) > 0, true
}
1075054
func (s *Server) Match(methods []string, path string, handler HandlerFunc, opts ...HandlerOption) {
	info := newHandlerInfo(handler, opts)
	s.registerInfo(path, info, methods...)
}
272029
func (a *assertion) Match(obtained, regex string, msgs ...string) bool {
	matches, err := a.IsMatching(obtained, regex)
	if err != nil {
		return a.failer.Fail(Match, obtained, regex, "can't compile regex: "+err.Error())
	}
	if !matches {
		return a.failer.Fail(Match, obtained, regex, msgs...)
	}
	return true
}
869448
func Match(pattern string, b []byte) (matched bool, err error) {
	re, err := Compile(pattern)
	if err != nil {
		return false, err
	}
	return re.Match(b), nil
}
801163
func (trie *Trie) Match(prefix Prefix) (matchedExactly bool) {
	return trie.Get(prefix) != nil
}
92644
func (s *Sublist) Match(subject string) []interface{} {
	s.RLock()
	rc, ok := s.cache[subject]
	s.RUnlock()
	if ok {
		return rc
	}

	tsa := [32]string{}
	tokens := tsa[:0]
	start := 0
	for i := 0; i < len(subject); i++ {
		if subject[i] == btsep {
			tokens = append(tokens, subject[start:i])
			start = i + 1
		}
	}
	tokens = append(tokens, subject[start:])
	result := make([]interface{}, 0, 4)

	s.Lock()
	matchLevel(s.root, tokens, &result)

	// Add to our cache
	s.cache[subject] = result
	// Bound the number of entries to sublistMaxCache
	if len(s.cache) > slCacheMax {
		for k := range s.cache {
			delete(s.cache, k)
			break
		}
	}
	s.Unlock()

	return result
}
415560
func (mux *ServeMux) match(path string) (h Handler, pattern string) {
	var n = 0
	for k, v := range mux.m {
		if !pathMatch(k, path) {
			continue
		}
		if h == nil || len(k) > n {
			n = len(k)
			h = v.h
			pattern = v.pattern
		}
	}
	return
}
76674
func (m *Encoders) Match(s string) (respond.Encoder, bool) {
	m.lock.RLock()
	defer m.lock.RUnlock()
	for k, v := range m.encoders {
		if strings.Contains(strings.ToLower(s), strings.ToLower(k)) {
			// match
			return v, true
		}
	}
	return nil, false
}
103512
func match(pattern, name string) bool {
	matched, _ := filepath.Match(pattern, name)
	return matched
}
655519
func Match(needles []string, knownAgents []string) bool {
	matched := 0
	failed := 0

	for _, needle := range needles {
		if strings.HasPrefix(needle, "/") && strings.HasSuffix(needle, "/") {
			needle = strings.TrimPrefix(needle, "/")
			needle = strings.TrimSuffix(needle, "/")

			if hasAgentMatching(needle, knownAgents) {
				matched++
			} else {
				failed++
			}

			continue
		}

		if hasAgent(needle, knownAgents) {
			matched++
		} else {
			failed++
		}
	}

	return failed == 0 && matched > 0
}
70651
func (rules Rules) Match(objectName string) TargetIDSet {
	targetIDs := NewTargetIDSet()

	for pattern, targetIDSet := range rules {
		if wildcard.MatchSimple(pattern, objectName) {
			targetIDs = targetIDs.Union(targetIDSet)
		}
	}

	return targetIDs
}
835561
func Match(pattern string, ref Reference) (bool, error) {
	matched, err := path.Match(pattern, ref.String())
	if namedRef, isNamed := ref.(Named); isNamed && !matched {
		matched, _ = path.Match(pattern, namedRef.Name())
	}
	return matched, err
}
1215349
func (action Action) Match(a Action) bool {
	return wildcard.Match(string(action), string(a))
}
769046
func (p *pattern) compile(tokens []*Token) Pattern {
	// what tokens do we have in this pattern?
	//      - ANY token means we can match to any depth
	//      - SEPARATOR means we have path rather than file matching
	_separator := false
	for _, _token := range tokens {
		switch _token.Type {
		case ANY:
			return p.any(tokens)
		case SEPARATOR:
			_separator = true
		}
	}

	// should we perform path or name/file matching?
	if _separator {
		return p.path(tokens)
	} else {
		return p.name(tokens)
	}
}
588178
func (p Path) Matches(other string) bool {
	if CaseSensitivePath {
		return strings.HasPrefix(string(p), other)
	}
	return strings.HasPrefix(strings.ToLower(string(p)), strings.ToLower(other))
}