// Returns the last component of a URL, i.e. anything after the last slash
// If there is no slash, returns the whole string
330029
func lastComponent(s string) string {
	lastSlash := strings.LastIndex(s, "/")
	if lastSlash != -1 {
		s = s[lastSlash+1:]
	}
	return s
}
825140
func JoinURL(originalURL string, paths ...interface{}) (joinedURL string, err error) {
	u, err := url.Parse(originalURL)
	if err != nil {
		return
	}

	var urlPaths = []string{u.Path}
	for _, p := range paths {
		urlPaths = append(urlPaths, fmt.Sprint(p))
	}

	if strings.HasSuffix(strings.Join(urlPaths, ""), "/") {
		u.Path = path.Join(urlPaths...) + "/"
	} else {
		u.Path = path.Join(urlPaths...)
	}

	joinedURL = u.String()
	return
}
125115
func getLastAddrInRange(ipRange string, subnetLen uint) string {
	var lastIP string

	if isSubnetIPRange(ipRange) {
		lastIP = strings.Split(ipRange, "-")[1]
	} else {
		lastIP = getLastAddrInSubnet(ipRange, subnetLen)
	}

	return lastIP
}
930823
func AbsoluteURLAsURL(req *http.Request, relative string) (*url.URL, error) {
	return url.Parse(AbsoluteURL(req, relative))
}
944987
func (p *PathSpec) AbsURL(in string, addLanguage bool) string {
	url, err := url.Parse(in)
	if err != nil {
		return in
	}

	if url.IsAbs() || strings.HasPrefix(in, "//") {
		return in
	}

	var baseURL string
	if strings.HasPrefix(in, "/") {
		u := p.BaseURL.URL()
		u.Path = ""
		baseURL = u.String()
	} else {
		baseURL = p.BaseURL.String()
	}

	if addLanguage {
		prefix := p.GetLanguagePrefix()
		if prefix != "" {
			hasPrefix := false
			// avoid adding language prefix if already present
			if strings.HasPrefix(in, "/") {
				hasPrefix = strings.HasPrefix(in[1:], prefix)
			} else {
				hasPrefix = strings.HasPrefix(in, prefix)
			}

			if !hasPrefix {
				addSlash := in == "" || strings.HasSuffix(in, "/")
				in = path.Join(prefix, in)

				if addSlash {
					in += "/"
				}
			}
		}
	}
	return MakePermalink(baseURL, in).String()
}
680848
func (b *Bdiscord) splitURL(url string) (string, string) {
	const (
		expectedWebhookSplitCount = 7
		webhookIdxID              = 5
		webhookIdxToken           = 6
	)
	webhookURLSplit := strings.Split(url, "/")
	if len(webhookURLSplit) != expectedWebhookSplitCount {
		b.Log.Fatalf("%s is no correct discord WebhookURL", url)
	}
	return webhookURLSplit[webhookIdxID], webhookURLSplit[webhookIdxToken]
}
1046915
func (s *Subdomains) URL(purl string, args ...string) string {
	info := s.Get(args...)
	if info == nil {
		return purl
	}
	if len(info.Host) < 1 {
		if s.Default == info.Name {
			return purl
		}
		return `/` + info.Name + purl
	}
	if len(s.Protocol) < 1 {
		return `http://` + info.Host + purl
	}
	return s.Protocol + `://` + info.Host + purl
}
396524
func ParseURL(urlStr string) (result *url.URL, err error) {
	result, err = url.Parse(urlStr)
	if result != nil && result.Scheme == "" {
		result = nil
		err = fmt.Errorf("invalid URL <%s>", urlStr)
	}
	return
}
716509
func (c *Commit) GetHTMLURL() string {
	if c == nil || c.HTMLURL == nil {
		return ""
	}
	return *c.HTMLURL
}
569580
func URLMustParse(s string) *url.URL {
	u, err := url.Parse(s)
	if err != nil {
		log.Errorf("Expected URL to parse: %q, got error: %v", s, err)
	}
	return u
}
81166
func crawlTitleFromURL(link string) string {
	_title := strings.Split(link, "/")
	title := strings.Split(_title[4], "-ft-")

	title[0] = strings.Replace(title[0], "-", " ", -1)

	return title[0]
}
613556
func (i *item) URL() *url.URL {
	str, err := i.bucket.FileURL(i.name)
	if err != nil {
		return nil
	}

	url, _ := url.Parse(str)
	url.Scheme = Kind

	return url
}
941713
func GetRegionFromURL(endpointURL url.URL) string {
	if endpointURL == sentinelURL {
		return ""
	}
	if endpointURL.Host == "s3-external-1.amazonaws.com" {
		return ""
	}
	if IsAmazonGovCloudEndpoint(endpointURL) {
		return "us-gov-west-1"
	}
	parts := amazonS3HostDualStack.FindStringSubmatch(endpointURL.Host)
	if len(parts) > 1 {
		return parts[1]
	}
	parts = amazonS3HostHyphen.FindStringSubmatch(endpointURL.Host)
	if len(parts) > 1 {
		return parts[1]
	}
	parts = amazonS3ChinaHost.FindStringSubmatch(endpointURL.Host)
	if len(parts) > 1 {
		return parts[1]
	}
	parts = amazonS3HostDot.FindStringSubmatch(endpointURL.Host)
	if len(parts) > 1 {
		return parts[1]
	}
	return ""
}
233806
func (c *Client) URL(uri string) *Client {
	c.Use(url.URL(uri))
	return c
}
87334
func (loc *Location) URL() string {
	base, _ := url.Parse(loc.opts.SitemapsHost())

	for _, ref := range []string{
		loc.opts.sitemapsPath + "/", loc.Filename(),
	} {
		base, _ = base.Parse(ref)
	}

	return base.String()
}
510625
func (h *urlDataSource) URL(path string) (string, error) {
	return utils.MakeFileURL(urlJoin(h.baseURL, path)), nil
}
400672
func (r *Request) URL(uri string) *Request {
	r.Use(url.URL(uri))
	return r
}