// parsePattern support multi pattern
547043
func parsePattern(parent *Node, segments []string) *Node {
	segment := segments[0]
	segments = segments[1:]
	child := parseSegment(parent, segment)
	if len(segments) == 0 {
		child.endpoint = true
		return child
	}
	return parsePattern(child, segments)
}
197036
func (g Glob) Pattern() string {
	chunks := strings.SplitN(string(g), ":", 2)
	if len(chunks) != 2 {
		return ""
	}
	return chunks[1]
}
1346195
func (s *sqlStatement) MatchPatterns(str string) bool {
	for _, pattern := range s.patterns {
		if !pattern.MatchString(str) {
			return false
		}
	}
	return true
}
869809
func (o *GetFqdnCacheParams) bindMatchpattern(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false
	if raw == "" { // empty values pass all other validations
		return nil
	}

	o.Matchpattern = &raw

	return nil
}
257215
func (p *Pattern) genaratePattern() {
	if p.Generator == "" {
		p.Generator = PATTERNS[int(utils.HexVal(p.Hash, 20, 1))]
	} else {
		if !isPattern(p.Generator) {
			panic("Error: the requested generator is invalid.")
		}
	}

	switch p.Generator {
	case "chevrons":
		p.geoChevrons()
	case "concentric-circles":
		p.geoConcentricCircles()
	case "diamonds":
		p.geoDiamonds()
	case "hexagons":
		p.geoHexagons()
	case "mosaic-squares":
		p.geoMosaicSquares()
	case "nested-squares":
		p.geoNestedSquares()
	case "octagons":
		p.geoOctagons()
	case "overlapping-circles":
		p.geoOverlappingCircles()
	case "overlapping-rings":
		p.geoOverlappingRings()
	case "plaid":
		p.geoPlaid()
	case "plus-signs":
		p.geoPlusSigns()
	case "sine-waves":
		p.geoSineWaves()
	case "squares":
		p.geoSquares()
	case "tessellation":
		p.geoTessellation()
	case "triangles":
		p.geoTriangles()
	case "xes":
		p.geoXes()
	}
}
446072
func (s *OptionRestrictionRegex) SetPattern(v string) *OptionRestrictionRegex {
	s.Pattern = &v
	return s
}
214945
func patternMatch(str string, patChars, patTypes []byte) bool {
	return stringutil.DoMatch(str, patChars, patTypes)
}
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
}
1299394
func compilePattern(pattern string, escape byte) (patChars, patTypes []byte) {
	var lastAny bool
	patChars = make([]byte, len(pattern))
	patTypes = make([]byte, len(pattern))
	patLen := 0
	for i := 0; i < len(pattern); i++ {
		var tp byte
		var c = pattern[i]
		switch c {
		case escape:
			lastAny = false
			tp = patMatch
			if i < len(pattern)-1 {
				i++
				c = pattern[i]
				if c == escape || c == '_' || c == '%' {
					// valid escape.
				} else {
					// invalid escape, fall back to escape byte
					// mysql will treat escape character as the origin value even
					// the escape sequence is invalid in Go or C.
					// e.g, \m is invalid in Go, but in MySQL we will get "m" for select '\m'.
					// Following case is correct just for escape \, not for others like +.
					// TODO: add more checks for other escapes.
					i--
					c = escape
				}
			}
		case '_':
			lastAny = false
			tp = patOne
		case '%':
			if lastAny {
				continue
			}
			lastAny = true
			tp = patAny
		default:
			lastAny = false
			tp = patMatch
		}
		patChars[patLen] = c
		patTypes[patLen] = tp
		patLen++
	}
	for i := 0; i < patLen-1; i++ {
		if (patTypes[i] == patAny) && (patTypes[i+1] == patOne) {
			patTypes[i] = patOne
			patTypes[i+1] = patAny
		}
	}
	patChars = patChars[:patLen]
	patTypes = patTypes[:patLen]
	return
}
1239419
func GetFuncNameByPattern(
	pattern string,
	repl func(string) string,
) string {
	result := GetAPINameByPattern(pattern, repl)
	versionInfos := regexpAPIVersionPrefix.FindStringSubmatch(pattern)
	if len(versionInfos) > 1 {
		result += "V" + versionInfos[1]
	}
	return result
}
1053961
func (tc *WildcardTopicsToNumStreams) Pattern() string {
	switch tc.TopicFilter.(type) {
	case *WhiteList:
		return whiteListPattern
	case *BlackList:
		return blackListPattern
	default:
		panic("unknown topic filter")
	}
}
1102152
func parseCacheDrivePaths(arg string) (ep []string, err error) {
	patterns, perr := ellipses.FindEllipsesPatterns(arg)
	if perr != nil {
		return []string{}, uiErrInvalidCacheDrivesValue(nil).Msg(perr.Error())
	}

	for _, lbls := range patterns.Expand() {
		ep = append(ep, strings.Join(lbls, ""))
	}

	return ep, nil
}
370527
func MustParse(s string) Pattern {
	pattern, err := Parse(s)
	if err != nil {
		panic(err)
	}
	return pattern
}
1181795
func parsePrefix(s string) (string, string) {
	if strings.HasPrefix(s, "P") {
		return "P", s[1:]
	}
	if len(s) < 2 {
		return s, ""
	}
	return s[:2], s[2:]
}
636789
func InvalidPatternError(ctx, target string, pattern string) error {
	msg := fmt.Sprintf("%s must match the regexp %#v but got value %#v", ctx, pattern, target)
	return ErrInvalidRequest(msg, "attribute", ctx, "value", target, "regexp", pattern)
}
676843
func (c Calendar) parseDateTimeFormat(pattern string) ([]*datetimePatternComponent, error) {
	// every thing between single quotes should become a literal
	// all non a-z, A-Z characters become a literal
	// everything else, repeat character sequences become a component
	format := []*datetimePatternComponent{}
	for i := 0; i < len(pattern); {
		char := pattern[i : i+1]

		skip := false
		// for units we don't support yet, just skip over them
		for _, r := range datetimeFormatUnitCutset {
			if char == string(r) {
				skip = true
				break
			}
		}

		if skip {
			i++
			continue
		}

		if char == string(datetimeFormatLiteral) {
			// find the next single quote
			// create a literal out of everything between the quotes
			// and set i to the position after the second quote

			if i == len(pattern)-1 {
				return []*datetimePatternComponent{}, errors.New("malformed datetime format")
			}

			nextQuote := strings.Index(pattern[i+1:], string(datetimeFormatLiteral))
			if nextQuote == -1 {
				return []*datetimePatternComponent{}, errors.New("malformed datetime format")
			}

			component := &datetimePatternComponent{
				pattern:       pattern[i+1 : nextQuote+i+1],
				componentType: datetimePatternComponentLiteral,
			}

			format = append(format, component)
			i = nextQuote + i + 2
			continue

		}
		if (char >= "a" && char <= "z") || (char >= "A" && char <= "Z") {
			// this represents a format unit
			// find the entire sequence of the same character
			endChar := lastSequenceIndex(pattern[i:]) + i

			component := &datetimePatternComponent{
				pattern:       pattern[i : endChar+1],
				componentType: datetimePatternComponentUnit,
			}

			format = append(format, component)
			i = endChar + 1
			continue

		}
		if char == string(datetimeFormatTimeSeparator) {
			component := &datetimePatternComponent{
				// pattern:       c.TimeSeparator,
				pattern:       string(datetimeFormatTimeSeparator),
				componentType: datetimePatternComponentLiteral,
			}
			format = append(format, component)
			i++
			continue

		}

		component := &datetimePatternComponent{
			pattern:       char,
			componentType: datetimePatternComponentLiteral,
		}

		format = append(format, component)
		i++
		continue

	}

	return format, nil
}
374793
func (s *CreateGrokClassifierRequest) SetGrokPattern(v string) *CreateGrokClassifierRequest {
	s.GrokPattern = &v
	return s
}