// URLStringForPath returns an URL as string with file scheme for path.
// For example,
//     /usr/local/go/bin => file:///usr/local/go/bin
//     C:\Go\bin => file:///C:/Go/bin
964747
func URLStringForPath(path string) string {
	if runtime.GOOS == "windows" {
		path = convertPathForWindows(path)
	}
	u := &url.URL{Path: path}
	encodedPath := u.String()
	return fmt.Sprintf("%s://%s", fileScheme, encodedPath)
}
478912
func getIntelRdtParamString(path, file string) (string, error) {
	contents, err := ioutil.ReadFile(filepath.Join(path, file))
	if err != nil {
		return "", err
	}

	return strings.TrimSpace(string(contents)), nil
}
927791
func (f *FileNameV3) Path() string {
	return (&FileName{Name: f.Name, Length: f.Length}).Path()
}
640408
func (ut *URLTransformer) LoadPaths(paths []string) error {
	for _, path := range paths {
		err := ut.LoadPath(path)
		if err != nil {
			return err
		}
	}
	return nil
}
1312687
func (f FileSystem) GetFullPath(url string, option *Option) (path string, err error) {
	if option != nil && option.Get("path") != "" {
		path = filepath.Join(option.Get("path"), url)
	} else {
		path = filepath.Join("./public", url)
	}

	dir := filepath.Dir(path)
	if _, err := os.Stat(dir); os.IsNotExist(err) {
		err = os.MkdirAll(dir, os.ModePerm)
	}

	return
}
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
}
534909
func GoPath() string {
	if path := os.Getenv("GOPATH"); path != "" {
		return path
	}
	// https://github.com/golang/go/issues/17262
	return filepath.Join(os.Getenv("HOME"), "go")
}
510625
func (h *urlDataSource) URL(path string) (string, error) {
	return utils.MakeFileURL(urlJoin(h.baseURL, path)), nil
}
247177
func (c *Conf) Path() string {
	return fmt.Sprintf("%s/%s", c.dirPath, c.fileName)
}
631403
func (c *Clair) url(pathTemplate string, args ...interface{}) string {
	pathSuffix := fmt.Sprintf(pathTemplate, args...)
	url := fmt.Sprintf("%s%s", c.URL, pathSuffix)
	return url
}
1306498
func RawPath(in string) (string, error) {
	u, err := url.ParseRequestURI(in)
	if err != nil {
		return "", err
	}
	path := ""
	if u.Opaque != "" {
		path = u.Opaque
	} else if u.Host == "" {
		path = in
	} else {
		vals := strings.SplitN(in, u.Host, 2)
		if len(vals) != 2 {
			return "", fmt.Errorf("failed to parse url")
		}
		path = vals[1]
	}
	idx := strings.IndexRune(path, '?')
	if idx == -1 {
		return path, nil
	}
	return path[:idx], nil
}
817569
func CommonPath(path1, path2 string) string {
	parts1 := strings.Split(path1, "/")
	parts2 := strings.Split(path2, "/")
	maxIdx := len(parts1)
	if len(parts2) < maxIdx {
		maxIdx = len(parts2)
	}

	common := make([]string, 0, maxIdx)
	for i := 0; i < maxIdx; i++ {
		if parts1[i] == parts2[i] {
			common = append(common, parts1[i])
		}
	}

	return strings.Join(common, "/")
}
161333
func BinPath() (string, error) {
	exePath, err := os.Executable()
	if err != nil {
		return "", err
	}
	return filepath.EvalSymlinks(exePath)
}
201791
func (r *Request) AddPath(path string) *Request {
	r.Use(url.AddPath(path))
	return r
}
1210704
func (p *PathSpec) PermalinkForBaseURL(link, baseURL string) string {
	link = strings.TrimPrefix(link, "/")
	if !strings.HasSuffix(baseURL, "/") {
		baseURL += "/"
	}
	return baseURL + link

}
224502
func DigestForFileAtPath(path string) (string, error) {
	f, err := os.Open(path)
	if err != nil {
		return "", err
	}
	defer f.Close()
	return Digest(f)
}
81737
func uriPathToFilename(uriPath string) string {
	if runtime.GOOS != "windows" {
		return uriPath
	}

	// Convert slashes and remove first `/` left over from the URI path since
	// absolute path on Windows won't start with `\`.
	filename := strings.TrimPrefix(uriPath, `/`)
	return filepath.FromSlash(filename)
}