// SplitPattern splits a pattern into a root directory and a trailing pattern
// specifier.
557760
func SplitPattern(pattern string) (string, string) {
	base := pattern
	trail := ""

	split := strings.IndexAny(pattern, "*{}?[]")
	if split >= 0 {
		base = pattern[:split]
		trail = pattern[split:]
	}
	return base, trail
}
290163
func splitTokens(tokens []string, sep string) (s splitted, err error) {
	index := index(tokens, sep)
	if index == -1 {
		return s, fmt.Errorf("'%s' not found in ['%s']", sep, strings.Join(tokens, "','"))
	}
	return splitted{
		Left:  tokens[:index],
		Right: tokens[index+1:],
	}, nil
}
1188988
func splitCombine(inStrs []string) []string {
	outStrs := make([]string, 0)
	for _, str := range inStrs {
		inStrs := strings.Fields(str)
		outStrs = append(outStrs, inStrs...)
	}
	return outStrs
}
27391
func generatePatterns(url string) ([]string, error) {
	hosts, err := generateLookupHosts(url)
	if err != nil {
		return nil, err
	}
	paths, err := generateLookupPaths(url)
	if err != nil {
		return nil, err
	}
	var patterns []string
	for _, h := range hosts {
		for _, p := range paths {
			patterns = append(patterns, h+p)
		}
	}
	return patterns, nil
}
137132
func SplitPrefix(path string) ([]string, string) {
	parts := strings.SplitN(path, ":", 2)
	if len(parts) == 2 && len(parts[0]) > 0 {
		return strings.Split(parts[0], "."), parts[1]
	}
	return nil, path
}
666087
func SplitPath(p string) []string {
	dir, file := filepath.Split(p)
	if dir == "" || dir == "/" {
		return []string{file}
	}
	dir = filepath.Clean(dir)
	return append(SplitPath(dir), file)
}
119178
func splitMethodName(fullMethodName string) (string, string) {
	fullMethodName = strings.TrimPrefix(fullMethodName, "/") // remove leading slash
	if i := strings.Index(fullMethodName, "/"); i >= 0 {
		return fullMethodName[:i], fullMethodName[i+1:]
	}
	return "unknown", "unknown"
}
756525
func (tree *tree) split(pattern string) (out []*node) {
	base := pattern
	for {
		if pattern == "" {
			break
		}
		c := pattern[0]

		var endinglabel byte

		end := strings.IndexAny(pattern, tree.Separators())
		if end < 0 {
			end = len(pattern)
			endinglabel = pattern[end-1]
		} else {
			endinglabel = pattern[end]
		}

		var child *node
		switch c {
		case tree.ParamChar():
			var l byte
			idx := strings.Index(base, pattern[:end])
			if idx > 0 {
				l = base[idx-1]
			}

			endinglabel = 0
			if len(pattern) > end {
				endinglabel = pattern[end]
			}

			child = &node{
				pattern:     pattern[:end],
				nodeType:    param,
				pname:       pattern[1:end],
				endinglabel: endinglabel,
				label:       l,
			}

			// Check if this param contains a regex definition
			parenthesisIdx := strings.Index(pattern[:end], "(")
			if parenthesisIdx > 0 { // Regex param
				startp, endp := nextParenthesis(pattern)
				child.re = regexp.MustCompile(pattern[startp+1 : endp])

				// Update child
				end = endp + 1
				child.pname = pattern[1:startp]
				child.pattern = pattern[:end]
				child.endinglabel = pattern[end-1]
			}

			out = append(out, child)
		case tree.WildcardChar():
			pname := pattern[1:]
			if pname == "" {
				pname = "*"
			}
			child = &node{
				pattern:  pattern,
				nodeType: wildcard,
				pname:    pname,
			}

			out = append(out, child)
			pattern = ""
			continue
		default:
			charIdx := stringsIndexAnyNotEscaped(pattern, tree.AllChars())
			if charIdx < 0 {
				charIdx = len(pattern)
			}

			count := strings.Count(pattern[:charIdx], `\`)
			charIdx -= count
			pattern = strings.Replace(pattern, `\`, "", count)

			end = charIdx

			cp := pattern[:end]
			endinglabel = cp[len(cp)-1]
			pattern = pattern[end:]

			child = &node{
				pattern:     cp,
				nodeType:    static,
				label:       c,
				endinglabel: endinglabel,
			}

			out = append(out, child)
			continue
		}
		pattern = pattern[end:]
	}

	return
}
67785
func treeCanMatchPattern(pattern string) func(name string) bool {
	wildCard := false
	if i := strings.Index(pattern, "..."); i >= 0 {
		wildCard = true
		pattern = pattern[:i]
	}
	return func(name string) bool {
		return len(name) <= len(pattern) && hasPathPrefix(pattern, name) ||
			wildCard && strings.HasPrefix(name, pattern)
	}
}
39890
func SplitStringFunction(env *Zlisp, name string, args []Sexp) (Sexp, error) {
	if len(args) != 2 {
		return SexpNull, WrongNargs
	}

	// make sure the two args are strings
	s1, ok := args[0].(*SexpStr)
	if !ok {
		return SexpNull, fmt.Errorf("split requires a string to split, got %T", args[0])
	}
	s2, ok := args[1].(*SexpStr)
	if !ok {
		return SexpNull, fmt.Errorf("split requires a string as a delimiter, got %T", args[1])
	}

	toSplit := s1.S
	splitter := s2.S
	s := strings.Split(toSplit, splitter)

	split := make([]Sexp, len(s))
	for i := range split {
		split[i] = &SexpStr{S: s[i]}
	}

	return env.NewSexpArray(split), nil
}
1074347
func FailedPattern(name, in, pattern string) *Validation {
	var msg string
	if in == "" {
		msg = fmt.Sprintf(patternFailNoIn, name, pattern)
	} else {
		msg = fmt.Sprintf(patternFail, name, in, pattern)
	}

	return &Validation{
		code:    PatternFailCode,
		Name:    name,
		In:      in,
		message: msg,
	}
}
1264138
func splitPath(path string) ([]fileInfo, error) {
	var mode os.FileMode
	fi, err := os.Stat(path)

	// If the path is not present in the host then we respond with the most
	// flexible permission.
	uid, gid := idUnsupported, idUnsupported
	if err != nil {
		mode = os.ModePerm
	} else {
		uid, gid = getOwner(fi)
		mode = fi.Mode()
	}
	var dirs []fileInfo
	dirs = append(dirs, fileInfo{Name: path, Perm: mode, Uid: uid, Gid: gid})
	currentDir := path
	for {
		dir := filepath.Dir(filepath.Clean(currentDir))
		if dir == currentDir {
			break
		}

		// We try to find the permission of the file in the host. If the path is not
		// present in the host then we respond with the most flexible permission.
		uid, gid := idUnsupported, idUnsupported
		fi, err := os.Stat(dir)
		if err != nil {
			mode = os.ModePerm
		} else {
			uid, gid = getOwner(fi)
			mode = fi.Mode()
		}
		dirs = append(dirs, fileInfo{Name: dir, Perm: mode, Uid: uid, Gid: gid})
		currentDir = dir
	}
	return dirs, nil
}
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)
}
92738
func (s *TopicRuleListItem) SetTopicPattern(v string) *TopicRuleListItem {
	s.TopicPattern = &v
	return s
}
71450
func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) {
	var pids []PID
	procs, err := getWin32ProcsByVariable("CommandLine", like, pattern, Timeout)
	if err != nil {
		return pids, err
	}
	for _, p := range procs {
		pids = append(pids, PID(p.ProcessID))
	}
	return pids, nil
}
1053961
func (tc *WildcardTopicsToNumStreams) Pattern() string {
	switch tc.TopicFilter.(type) {
	case *WhiteList:
		return whiteListPattern
	case *BlackList:
		return blackListPattern
	default:
		panic("unknown topic filter")
	}
}
722452
func splitPath(path string) []string {
	if path[0] == '/' {
		path = path[1:]
	}
	// Count parts to avoid growing slice.
	var n uint16
	for i := 0; i < len(path); i++ {
		n++
		p := strings.IndexByte(path[i:], '/')
		if p == -1 {
			break
		}
		if p == len(path)-1 { // Also count trailing slash.
			n++
		}
		i = p + i
	}
	s := make([]string, 0, n)
	for {
		p := strings.IndexByte(path, '/')
		if p == -1 {
			s = append(s, path)
			break
		}
		s = append(s, path[:p])
		path = path[p+1:]
	}
	return s
}