// stripURLParts removes path, protocol & query from url and returns it.
482906
func stripURLParts(url string) string {
	// Lower case the url
	url = strings.ToLower(url)

	// Strip protocol
	if index := strings.Index(url, "://"); index > -1 {
		url = url[index+3:]
	}

	// Now, if the url looks like this: username:password@www.example.com/path?query=?
	// we remove the content before the '@' symbol
	if index := strings.Index(url, "@"); index > -1 {
		url = url[index+1:]
	}

	// Strip path (and query with it)
	if index := strings.Index(url, "/"); index > -1 {
		url = url[:index]
	} else if index := strings.Index(url, "?"); index > -1 { // Strip query if path is not found
		url = url[:index]
	}

	// Convert domain to unicode
	if strings.Index(url, "xn--") != -1 {
		var err error
		url, err = idna.ToUnicode(url)
		if err != nil {
			return ""
		}
	}

	// Return domain
	return url
}
783293
func isURLOrHostPort(s string) bool {
	return strings.HasPrefix(s, "http://") ||
		strings.HasPrefix(s, "https://") ||
		strings.Contains(s, ".") || strings.Contains(s, ":")
}
402314
func (p *PathSpec) URLPrep(in string) string {
	if p.UglyURLs {
		return Uglify(SanitizeURL(in))
	}
	pretty := PrettifyURL(SanitizeURL(in))
	if path.Ext(pretty) == ".xml" {
		return pretty
	}
	url, err := purell.NormalizeURLString(pretty, purell.FlagAddTrailingSlash)
	if err != nil {
		return pretty
	}
	return url
}
1252959
func StripDefaultNS(v string) string {
	if idx := strings.IndexByte(v, '/'); idx > 0 {
		if v[:idx] == api.IntentionDefaultNamespace {
			return v[:idx+1]
		}
	}

	return v
}
166330
func stripTrailingSlashes(path string) string {
	if len(path) > 0 && path[len(path)-1] == '/' {
		path = path[0 : len(path)-1]
	}

	return path
}
1072508
func URLFilters(filters ...*regexp.Regexp) func(*Collector) {
	return func(c *Collector) {
		c.URLFilters = filters
	}
}
690580
func StripScheme(t Transport, addr string) (string, error) {
	if !strings.HasPrefix(addr, t.Scheme()+"://") {
		return addr, ErrBadTran
	}
	return addr[len(t.Scheme()+"://"):], nil
}
409530
func (p *PathSpec) URLEscape(uri string) string {
	// escape unicode letters
	parsedURI, err := url.Parse(uri)
	if err != nil {
		// if net/url can not parse URL it means Sanitize works incorrectly
		panic(err)
	}
	x := parsedURI.String()
	return x
}
1055476
func GitilesRepoURL(c *pb.GitilesCommit) string {
	return fmt.Sprintf("https://%s/%s", c.Host, c.Project)
}
1182023
func urlParse(name string) *url.URL {
	var info os.FileInfo

	u, err := url.Parse(name)
	if err == nil && u.Scheme == "" {
		info, err = os.Stat(u.Path)
		if err == nil && info.IsDir() {
			u.Scheme = ArchiveScheme // special case for IsDir()
			return u
		}
	}

	u, err = url.Parse(strings.TrimPrefix(name, "/")) // must appear to be an absolute path or hgfs errors
	if err != nil {
		u = &url.URL{Path: name}
	}

	if u.Scheme == "" {
		ix := strings.Index(u.Path, "/")
		if ix > 0 {
			u.Scheme = u.Path[:ix]
			u.Path = u.Path[ix:]
		}
	}

	return u
}
55547
func trimURLPath(path string) string {
	parts := strings.SplitN(strings.TrimPrefix(path, "/"), "/", 3)
	if len(parts) == 0 {
		return path
	}

	if parts[0] == "metrics" && len(parts) > 1 {
		return fmt.Sprintf("%s/%s", parts[0], parts[1])

	}
	return parts[0]
}
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)
	}
}
495115
func (c *Config) AddrParts(address string) (string, int, error) {
	checkAddr := address

START:
	_, _, err := net.SplitHostPort(checkAddr)
	if ae, ok := err.(*net.AddrError); ok && ae.Err == "missing port in address" {
		checkAddr = fmt.Sprintf("%s:%d", checkAddr, DefaultBindPort)
		goto START
	}
	if err != nil {
		return "", 0, err
	}

	// Get the address
	addr, err := net.ResolveTCPAddr("tcp", checkAddr)
	if err != nil {
		return "", 0, err
	}

	return addr.IP.String(), addr.Port, nil
}
829226
func httpsOrHTTP(importPath string) (urlStr string, body io.ReadCloser, err error) {
	fetch := func(scheme string) (urlStr string, res *http.Response, err error) {
		u, err := url.Parse(scheme + "://" + importPath)
		if err != nil {
			return "", nil, err
		}
		u.RawQuery = "go-get=1"
		urlStr = u.String()
		if buildV {
			log.Printf("Fetching %s", urlStr)
		}
		res, err = httpClient.Get(urlStr)
		return
	}
	closeBody := func(res *http.Response) {
		if res != nil {
			res.Body.Close()
		}
	}
	urlStr, res, err := fetch("https")
	if err != nil || res.StatusCode != 200 {
		if buildV {
			if err != nil {
				log.Printf("https fetch failed.")
			} else {
				log.Printf("ignoring https fetch with status code %d", res.StatusCode)
			}
		}
		closeBody(res)
		urlStr, res, err = fetch("http")
	}
	if err != nil {
		closeBody(res)
		return "", nil, err
	}
	// Note: accepting a non-200 OK here, so people can serve a
	// meta import in their http 404 page.
	if buildV {
		log.Printf("Parsing meta tags from %s (status code %d)", urlStr, res.StatusCode)
	}
	return urlStr, res.Body, nil
}
569862
func parseLyticsURL(url string, params map[string]string) string {
	out := url

	for key, value := range params {
		out = strings.Replace(out, fmt.Sprintf(":%s", key), value, -1)
	}

	return out
}
1002459
func OptionallyHTTPSFormattedURLString(bareURLString string, https bool) (string, bool) {
	httpsFormattedString := bareURLString
	isHTTPSchemedURL := false

	if u, parseErr := url.Parse(bareURLString); parseErr == nil {
		isHTTPSchemedURL = u.Scheme == "http"
	}

	if isHTTPSchemedURL && https {
		httpsFormattedString = strings.Replace(bareURLString, "http", "https", 1)
	}

	return httpsFormattedString, isHTTPSchemedURL
}
739682
func stripLayerID(layerName string) string {
	n := strings.LastIndex(layerName, "-")
	return layerName[:n]
}