// stripPathShortcuts removes any leading or trailing "../" from a given path
769268
func stripPathShortcuts(p string) string {
	newPath := path.Clean(p)
	trimmed := strings.TrimPrefix(newPath, "../")

	for trimmed != newPath {
		newPath = trimmed
		trimmed = strings.TrimPrefix(newPath, "../")
	}

	// trim leftover {".", ".."}
	if newPath == "." || newPath == ".." {
		newPath = ""
	}

	if len(newPath) > 0 && string(newPath[0]) == "/" {
		return newPath[1:]
	}

	return newPath
}
1106171
func SanitizePath(p string) string {
	if len(p) == 0 {
		return "/"
	}

	if !strings.HasPrefix(p, "/") {
		p = "/" + p
	}

	trailingSlash := strings.HasSuffix(p, "/")
	p = gopath.Clean(p)

	if p != "/" && trailingSlash {
		p += "/"
	}

	return p
}
578140
func (p *PathManager) AddPaths(paths []string) {
	p.l.Lock()
	defer p.l.Unlock()

	txn := p.paths.Txn()
	for _, prefix := range paths {
		if len(prefix) == 0 {
			continue
		}

		var exception bool
		if strings.HasPrefix(prefix, "!") {
			prefix = strings.TrimPrefix(prefix, "!")
			exception = true
		}

		// We trim any trailing *, but we don't touch whether it is a trailing
		// slash or not since we want to be able to ignore prefixes that fully
		// specify a file
		txn.Insert([]byte(strings.TrimSuffix(prefix, "*")), exception)
	}
	p.paths = txn.Commit()
}
732944
func (s *Spec) AllPaths() map[string]spec.PathItem {
	if s.spec == nil || s.spec.Paths == nil {
		return nil
	}
	return s.spec.Paths.Paths
}
1224774
func AllPaths(dir string) (map[string]bool, error) {
	m := make(map[string]bool)
	return m, allPaths(m, nil, dir)
}
1352301
func ParsePathEscaped(str string) (path Path, ok bool) {
	path, ok = ParsePath(str)
	if !ok {
		return
	}
	for i := range path {
		segment, err := url.PathUnescape(path[i])
		if err == nil {
			path[i] = segment
		}
	}
	return
}
615372
func profileShortcuts(p *profile.Profile) shortcuts {
	s := pprofShortcuts
	// Add shortcuts for sample types
	for _, st := range p.SampleType {
		command := fmt.Sprintf("sample_index=%s", st.Type)
		s[st.Type] = []string{command}
		s["total_"+st.Type] = []string{"mean=0", command}
		s["mean_"+st.Type] = []string{"mean=1", command}
	}
	return s
}
684364
func SassOptionSetIncludePath(goopts SassOptions, path string) {
	C.sass_option_set_include_path(goopts, C.CString(path))
}
463752
func trimExeSuffix(s string) (string, error) {
	ext := filepath.Ext(s)
	if ext == "" {
		return "", errors.Errorf("path %q lacks required file extension", s)
	}

	exe := ".exe"
	if !strings.EqualFold(ext, exe) {
		return "", errors.Errorf("path %q lacks required %q suffix", s, exe)
	}
	return strings.TrimSuffix(s, ext), nil
}
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
}
1186328
func StripPrefix(strip bool) source.Option {
	return func(o *source.Options) {
		if o.Context == nil {
			o.Context = context.Background()
		}

		o.Context = context.WithValue(o.Context, stripPrefixKey{}, strip)
	}
}
586420
func goSliceRawSlice(s string) []string {
	s = strings.TrimPrefix(s, "[")
	s = strings.TrimSuffix(s, "]")
	s = strings.TrimSpace(s)
	if s == "" {
		return nil
	}
	a := strings.Split(s, " ")
	return a
}
265287
func subdirs(path string) (paths []string) {
	filepath.Walk(path, func(subpath string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}

		if info.IsDir() {
			name := info.Name()
			hidden := filepath.HasPrefix(name, ".") && name != "." && name != ".."
			if hidden {
				return filepath.SkipDir
			}
			paths = append(paths, subpath)
		}
		return nil
	})
	return paths
}
60127
func StripComments(file []byte) []byte {
	stripped := file
	stripped, err := yaml.ToJSON(stripped)
	if err != nil {
		stripped = ManualStrip(file)
	}
	return stripped
}
688709
func PathLsNTypeNot(basePath string, depth int, filetypes []string) (map[int]string, error) {
	return doPathWalk(basePath, depth, filetypes, false)
}
1181
func stripPrefix(key []byte, prefix []byte) (stripped []byte) {
	if len(key) < len(prefix) {
		panic("should not happen")
	}
	if !bytes.Equal(key[:len(prefix)], prefix) {
		panic("should not happne")
	}
	return key[len(prefix):]
}
1183864
func normalizePathSeparator(p string) string {
	if filepath.Separator == '/' {
		return strings.Replace(p, `\`, string(filepath.Separator), -1)
	}
	return strings.Replace(p, "/", string(filepath.Separator), -1)
}