// ParsePattern parses a gitattributes pattern string into the Pattern
// structure.
14087
func ParsePattern(p string, domain []string) Pattern {
	return &pattern{
		domain:  domain,
		pattern: strings.Split(p, patternDirSep),
	}
}
754537
func hasPattern(patterns []string, matchStr string) bool {
	for _, pattern := range patterns {
		if ok := wildcard.MatchSimple(pattern, matchStr); ok {
			return true
		}
	}
	return false
}
552791
func ValidatePattern(p string, val string) bool {
	knownPatternsLock.RLock()
	r, ok := knownPatterns[p]
	knownPatternsLock.RUnlock()
	if !ok {
		r = regexp.MustCompile(p) // DSL validation makes sure regexp is valid
		knownPatternsLock.Lock()
		knownPatterns[p] = r
		knownPatternsLock.Unlock()
	}
	return r.MatchString(val)
}
605165
func (s *Rule) SetEventPattern(v string) *Rule {
	s.EventPattern = &v
	return s
}
979463
func (db *DB) AddQueryPattern(queryPattern string, expectedResult *sqltypes.Result) {
	if len(expectedResult.Rows) > 0 && len(expectedResult.Fields) == 0 {
		panic(fmt.Errorf("please add Fields to this Result so it's valid: %v", queryPattern))
	}
	expr := regexp.MustCompile("(?is)^" + queryPattern + "$")
	result := *expectedResult
	db.mu.Lock()
	defer db.mu.Unlock()
	db.patternData = append(db.patternData, exprResult{expr, &result})
}
214945
func patternMatch(str string, patChars, patTypes []byte) bool {
	return stringutil.DoMatch(str, patChars, patTypes)
}
171626
func parseFormatStyleSet(style string) (*formatStyle, error) {
	format := formatStyle{
		DecimalPlaces: 2,
	}
	err := json.Unmarshal([]byte(style), &format)
	return &format, err
}
7364
func GetAPINameByPattern(
	pattern string,
	repl func(string) string,
) string {
	result := pattern
	result = regexpAPIVersionPrefix.ReplaceAllString(result, "")

	result = regexpAPIParam.ReplaceAllStringFunc(result, func(str string) string {
		param := str[1:]
		return "(?P<" + param + ">[^/]+)"
	})

	result = regexpAPIParam2.ReplaceAllStringFunc(result, func(str string) string {
		matches := regexpAPIParam2.FindStringSubmatch(str)
		param := matches[1]
		if repl == nil {
			return ""
		}
		return repl(param)
	})

	result = regexpAPISlashCamelCase.ReplaceAllStringFunc(result, func(str string) string {
		return strings.ToUpper(str[1:])
	})

	// remove all slash
	result = strings.Replace(result, "/", "", -1)

	return result
}
1346195
func (s *sqlStatement) MatchPatterns(str string) bool {
	for _, pattern := range s.patterns {
		if !pattern.MatchString(str) {
			return false
		}
	}
	return true
}
974258
func (o *GetFqdnCacheParams) WithMatchpattern(matchpattern *string) *GetFqdnCacheParams {
	o.SetMatchpattern(matchpattern)
	return o
}
746827
func cleanPatterns(patterns []string) ([]string, [][]string, bool, error) {
	// Loop over exclusion patterns and:
	// 1. Clean them up.
	// 2. Indicate whether we are dealing with any exception rules.
	// 3. Error if we see a single exclusion marker on it's own (!).
	cleanedPatterns := []string{}
	patternDirs := [][]string{}
	exceptions := false
	for _, pattern := range patterns {
		// Eliminate leading and trailing whitespace.
		pattern = strings.TrimSpace(pattern)
		if empty(pattern) {
			continue
		}
		if exclusion(pattern) {
			if len(pattern) == 1 {
				return nil, nil, false, errors.New("Illegal exclusion pattern: !")
			}
			exceptions = true
		}
		pattern = filepath.Clean(pattern)
		cleanedPatterns = append(cleanedPatterns, pattern)
		if exclusion(pattern) {
			pattern = pattern[1:]
		}
		patternDirs = append(patternDirs, strings.Split(pattern, "/"))
	}

	return cleanedPatterns, patternDirs, exceptions, nil
}
259463
func (s *WebhookFilter) SetPattern(v string) *WebhookFilter {
	s.Pattern = &v
	return s
}
817575
func MatchPattern(pattern string) MatcherFunc {
	r := regexp.MustCompile(pattern)
	return func(candidate string) bool {
		return r.MatchString(candidate)
	}
}
955630
func ReplacePattern(str, pattern, replace string) string {
	r, _ := regexp.Compile(pattern)
	return r.ReplaceAllString(str, replace)
}
876392
func pattern(in string) string {
	mode := rand.Intn(3)
	if mode == 0 {
		// in this mode, replaces a node with a wildcard
		parts := strings.Split(in, ".")
		parts[rand.Intn(len(parts))] = "*"
		return strings.Join(parts, ".")
	} else if mode == 1 {
		// randomly replace chars with a *
		// note that in 1/5 cases, nothing happens
		// and otherwise, sometimes valid patterns are produced,
		// but it's also possible to produce patterns that won't match anything (if '.' was taken out)
		if len(in) < 5 {
			log.Fatalf("metric %q too short for pattern replacement", in)
		}
		chars := rand.Intn(5)
		pos := rand.Intn(len(in) - chars)
		return in[0:pos] + "*" + in[pos+chars:]
	}
	// mode 3: do nothing :)
	return in
}
134205
func renderPatternString(pat string, sub func(name string) (string, error)) (pattern.Pattern, error) {
	var errs errors.MultiError
	out := placeholderRe.ReplaceAllStringFunc(pat, func(match string) string {
		name := match[2 : len(match)-1] // strip ${...}
		val, err := sub(name)
		if err != nil {
			errs = append(errs, err)
		}
		return val
	})
	if len(errs) != 0 {
		return nil, errs
	}
	return pattern.Parse(out)
}
296159
func ValidatePattern(ch *Changeset, field string, pattern string, opts ...Option) {
	val, exist := ch.changes[field]
	if !exist {
		return
	}

	options := Options{
		message: ValidatePatternErrorMessage,
	}
	options.apply(opts)

	if str, ok := val.(string); ok {
		match, _ := regexp.MatchString(pattern, str)
		if !match {
			msg := strings.Replace(options.message, "{field}", field, 1)
			AddError(ch, field, msg)
		}
		return
	}
}