// regularMatchesPathToken tests whether the regular expression part of routeToken matches the requestToken or all remaining tokens
// format routeToken is {someVar:someExpression}, e.g. {zipcode:[\d][\d][\d][\d][A-Z][A-Z]}
433811
func (c CurlyRouter) regularMatchesPathToken(routeToken string, colon int, requestToken string) (matchesToken bool, matchesRemainder bool) {
	regPart := routeToken[colon+1 : len(routeToken)-1]
	if regPart == "*" {
		if trace {
			traceLogger.Printf("wildcard parameter detected in route token %s that matches %s\n", routeToken, requestToken)
		}
		return true, true
	}
	matched, err := regexp.MatchString(regPart, requestToken)
	return (matched && err == nil), false
}
359823
func (gi *GitIgnore) MatchesPath(f string) bool {
	// Replace OS-specific path separator.
	f = strings.Replace(f, string(os.PathSeparator), "/", -1)

	matchesPath := false
	for _, ip := range gi.patterns {
		if ip.pattern.MatchString(f) {
			// If this is a regular target (not negated with a gitignore exclude "!" etc)
			if !ip.negate {
				matchesPath = true
			} else if matchesPath {
				// Negated pattern, and matchesPath is already set
				matchesPath = false
			}
		}
	}
	return matchesPath
}
372794
func escape(token string) string {
	token = strings.Replace(token, "~", "~0", -1)
	token = strings.Replace(token, "/", "~1", -1)
	return url.PathEscape(token)
}
565432
func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
	if r.regexpType != regexpTypeHost {
		if r.regexpType == regexpTypeQuery {
			return r.matchQueryString(req)
		}
		path := req.URL.Path
		if r.options.useEncodedPath {
			path = req.URL.EscapedPath()
		}
		return r.regexp.MatchString(path)
	}

	return r.regexp.MatchString(getHost(req))
}
210075
func (g *routeGroup) Match(methods []string, path string, h http.HandlerFunc) {
	for _, m := range methods {
		g.handle(m, path, h)
	}
}
436555
func (m *mapping) matches(req *http.Request) (match matchType, method string) {
	if !m.path.MatchString(req.URL.Path) {
		match, method = noMatch, ""
	} else if m.method != req.Method {
		match, method = pathMatch, m.method
	} else {
		match, method = fullMatch, m.method
	}
	return
}
1008486
func (this *Route) Match(method string, path string) (map[string]string, bool) {

	// If there is no Regex, compile one.
	if this.Regex == nil {
		this.Regex = this.CompileRegex(this.Path)
	}

	// Prime the params map.
	params := map[string]string{}

	// The string used for matching.
	matchPath := path

	// Test if this route matches the given "method" and "path".
	if method != this.Method || this.Regex.MatchString(matchPath) == false {
		return params, false
	}

	// Extract all params from the matched path.
	paramsList := this.Regex.FindAllStringSubmatch(path, -1)

	// For each found param, add it to the params map.
	for i, name := range this.ParamNames {
		params[name] = paramsList[0][i+1]
	}

	// Debug this stuff.
	// fmt.Println(this.Path)
	// fmt.Println(paramsList)
	// fmt.Println(params)
	// fmt.Println("")

	// Return the complete params map.
	return params, true
}
512038
func RegexMatch(key1 string, key2 string) bool {
	res, err := regexp.MatchString(key2, key1)
	if err != nil {
		panic(err)
	}
	return res
}
1036175
func (g *routeGroup) Match(methods []string, path string, h ...Handler) {
	for _, m := range methods {
		g.handle(m, path, h)
	}
}
367733
func Match(method string, route string, handler interface{}) {
	mainServer.addRoute(route, method, handler)
}
862961
func (pt *PathTemplate) Match(requestPath string) (bool, map[string]string) {
	if pt.PathTemplate == pt.httpHandlePath {
		// TODO ざっくりした実装なので後でリファクタリングすること
		if strings.HasPrefix(requestPath, pt.httpHandlePath) {
			return true, nil
		}
	}

	requestPathSplitted := strings.Split(requestPath, "/")
	if requiredLen, requestLen := len(pt.splittedPathTemplate), len(requestPathSplitted); requiredLen < requestLen {
		// I want to match /js/index.js to / :)
		requestPathSplitted = requestPathSplitted[0:requiredLen]
	} else if requiredLen != requestLen {
		return false, nil
	}

	params := make(map[string]string)
	for idx, s := range pt.splittedPathTemplate {
		reqPart := requestPathSplitted[idx]
		if pt.isVariables[idx] {
			if reqPart == "" {
				return false, nil
			}
			v, err := url.QueryUnescape(reqPart)
			if err != nil {
				v = reqPart
			}
			params[s[1:len(s)-1]] = v
		} else if s != reqPart {
			return false, nil
		} else {
			// match
		}
	}

	return true, params
}
415560
func (mux *ServeMux) match(path string) (h Handler, pattern string) {
	var n = 0
	for k, v := range mux.m {
		if !pathMatch(k, path) {
			continue
		}
		if h == nil || len(k) > n {
			n = len(k)
			h = v.h
			pattern = v.pattern
		}
	}
	return
}
234091
func (repo *LocalRepository) Matches(pathQuery string) bool {
	for _, p := range repo.Subpaths() {
		if p == pathQuery {
			return true
		}
	}

	return false
}
1260792
func templateToSwaggerPath(path string) string {
	// It seems like the right thing to do here is to just use
	// strings.Split(path, "/") but that breaks badly when you hit a url like
	// /{my_field=prefix/*}/ and end up with 2 sections representing my_field.
	// Instead do the right thing and write a small pushdown (counter) automata
	// for it.
	var parts []string
	depth := 0
	buffer := ""
	for _, char := range path {
		switch char {
		case '{':
			// Push on the stack
			depth++
			buffer += string(char)
			break
		case '}':
			if depth == 0 {
				panic("Encountered } without matching { before it.")
			}
			// Pop from the stack
			depth--
			buffer += string(char)
		case '/':
			if depth == 0 {
				parts = append(parts, buffer)
				buffer = ""
				// Since the stack was empty when we hit the '/' we are done with this
				// section.
				continue
			}
			buffer += string(char)
		default:
			buffer += string(char)
			break
		}
	}

	// Now append the last element to parts
	parts = append(parts, buffer)

	// Parts is now an array of segments of the path. Interestingly, since the
	// syntax for this subsection CAN be handled by a regexp since it has no
	// memory.
	re := regexp.MustCompile("{([a-zA-Z][a-zA-Z0-9_.]*).*}")
	for index, part := range parts {
		// If part is a resource name such as "parent", "name", "user.name", the format info must be retained.
		prefix := re.ReplaceAllString(part, "$1")
		if isResourceName(prefix) {
			continue
		}
		parts[index] = re.ReplaceAllString(part, "{$1}")
	}

	return strings.Join(parts, "/")
}
486297
func (t *vhostTrie) matchPath(remainingPath string) *vhostTrie {
	var longestMatch *vhostTrie
	for len(remainingPath) > 0 {
		ch := string(remainingPath[0])
		next, ok := t.edges[ch]
		if !ok {
			break
		}
		if next.site != nil {
			longestMatch = next
		}
		t = next
		remainingPath = remainingPath[1:]
	}
	return longestMatch
}
669468
func Path(pattern string) *Mux {
	return Match(func(ctx *c.Context) bool {
		if ctx.GetString("$phase") != "request" {
			return false
		}
		matched, _ := regexp.MatchString(pattern, ctx.Request.URL.Path)
		return matched
	})
}
927062
func (r *Router) FilterPath(path string, filter http.HandlerFunc) {
	pattern := path
	pattern = strings.Replace(pattern, "*", "(.+)", -1)
	pattern = strings.Replace(pattern, "**", "([^/]+)", -1)
	regex := regexp.MustCompile(pattern)
	r.Filter(func(w http.ResponseWriter, req *http.Request) {
		if regex.MatchString(req.URL.Path) { filter(w, req) }
	})
}