Compiles a route into a priority, static prefix, regex part and param names.
12880
protected function compileRoute(Route $route): array
    {
        $regex = '';
        $prefix = '';
        $prio = 0;
        $pre = true;
        
        $wildcard = false;
        
        foreach (\explode('/', $route->pattern) as $level => $entry) {
            if (!$level) {
                continue;
            }
            
            if ($wildcard) {
                throw new \RuntimeException('No additional path segments are allowed after wildcard matcher');
            }
            
            if ($pre) {
                $prefix .= '/';
            } else {
                $regex .= '/';
            }
            
            $prio += 1000;
            
            if (false === \strpos($entry, '{')) {
                if ($pre) {
                    $prefix .= $entry;
                } else {
                    $regex .= \preg_quote($entry, "'");
                }
                
                $prio += 2;
                
                continue;
            }
            
            $pre = false;
            
            $parts = \preg_split("'(\\{[^\\}]+\\})'", $entry, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY);
            $boost = 0;
            
            foreach ($parts as $part) {
                if ($part[0] != '{') {
                    $regex .= \preg_quote($part, "'");
                    $boost += 2;
                    
                    continue;
                }
                
                if (\substr($part, -2) == '*}') {
                    $regex .= '(.+)';
                    $wildcard = true;
                    
                    break;
                }
                
                $regex .= '([^/]+)';
                $boost -= 1;
            }
            
            if ($wildcard) {
                if (\count($parts) !== 1) {
                    throw new \RuntimeException('Wildcard patern must be the only placeholder of the last route level');
                }
                
                $prio -= 500;
            } else {
                $prio += $boost;
            }
        }
        
        return [
            $route,
            $prio,
            '/' . \ltrim($prefix, '/'),
            $regex
        ];
    }
1355566
private static function compileFound($routes, $matched){
    $route_vars = [];
    foreach($routes as $pos => $raw){
      $root = "R$pos";
      if(isset($matched[$root])){
        $root_length = strlen($root);
        $route_vars[$routes[$pos]] = [];
        foreach($matched as $key => $match){
          if(!is_numeric($key) && $key !== $root && $key !== 'all_urls'){
            $new_key = substr($key, $root_length+1);
            $route_vars[$routes[$pos]][$new_key] = array_pop($match);
          }
        }
      }
    }
    return $route_vars;
  }
946946
function RoutePattern(options) {
    // The route string are compiled to a regexp (if it isn't already)
    this.pathPattern = options.pathPattern;
    this.queryStringPattern = options.queryStringPattern;
    this.hashPattern = options.hashPattern;

    // The original routestring (optional)
    this.routeString = options.routeString;
  }
1276858
def match(self, route):
        
        _resource = trim_resource(self.resource)
        self.method = self.method.lower()
        resource_match = route.resource_regex.search(_resource)
        if resource_match is None:
            return None

        # build params and querystring
        params = resource_match.groupdict()
        querystring = params.pop("querystring", "")
        setattr(self, "param", params)
        setattr(self, "query", parse_querystring(querystring))

        return copy.deepcopy(self)
130874
function Router_buildQuery(params) {
        var data = [];
        Object.keys(params).forEach(function (key) {
            data.push(key + '=' + encodeURIComponent(params[key]));
        });
        return data.join('&');
    }
176695
function(route, args) {
        var index;

        // There is a requirement for this route.
        if (typeof(self.routes[route].requirements) != 'undefined') {
            // For each arguments.
            for (index in args) {
                // If there is a requirement.
                if (self.routes[route].requirements[index] != null) {
                    // Check if it is fulfilled.
                    var regTest = (new RegExp(self.routes[route].requirements[index]));
                    // If not, replace data with :argument.
                    if (!regTest.test(args[index])) {
                        args[index] = ':' + index
                    }
                }
            }
        }
        return args
    }
229203
static function compile($pattern, array $options = array())
    {
        $route = self::compilePattern($pattern, $options);

        // save compiled pattern
        $route['compiled'] = sprintf("#^%s$#xs", $route['regex']);
        $route['pattern'] = $pattern; // save pattern
        return $route;
    }
460652
private static function processUriParams(&$path, &$params) {
		// if the route path contains parameters like `:key`
		if (preg_match_all(static::REGEX_PATH_PARAMS, $path, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
			$previousMatchEnd = 0;
			$regexParts = [];

			// extract all parameter names and create a regex that matches URIs and captures the parameters' values
			foreach ($matches as $match) {
				// remember the boundaries of the full match (e.g. `:key`) in the subject
				$matchStart = $match[0][1];
				$matchEnd = $matchStart + strlen($match[0][0]);

				// keep the part between this one and the previous match and escape it for regex
				$regexParts[] = static::regexEscape(substr($path, $previousMatchEnd, $matchStart - $previousMatchEnd));

				// save the current parameter's name
				$params[] = $match[1][0];

				// insert an expression that will match the parameter's value
				$regexParts[] = static::REGEX_PATH_SEGMENT;

				// remember the end index of the current match
				$previousMatchEnd = $matchEnd;
			}

			// keep the part after the last match and escape it for regex
			$regexParts[] = static::regexEscape(substr($path, $previousMatchEnd));

			// replace the parameterized URI with a regex that matches the parameters' values
			$path = implode('', $regexParts);
		}
		// if the route path is not parameterized
		else {
			// just escape the path for literal usage in regex
			$path = static::regexEscape($path);
		}
	}
224766
def process_route(pattern, conditions, block = nil, values = [])
      route = @request.path_info
      route = '/' if route.empty? and not settings.empty_path_info?
      route = route[0..-2] if !settings.strict_paths? && route != '/' && route.end_with?('/')
      return unless params = pattern.params(route)

      params.delete("ignore") # TODO: better params handling, maybe turn it into "smart" object or detect changes
      force_encoding(params)
      original, @params = @params, @params.merge(params) if params.any?

      regexp_exists = pattern.is_a?(Mustermann::Regular) || (pattern.respond_to?(:patterns) && pattern.patterns.any? {|subpattern| subpattern.is_a?(Mustermann::Regular)} )
      if regexp_exists
        captures           = pattern.match(route).captures.map { |c| URI_INSTANCE.unescape(c) if c }
        values            += captures
        @params[:captures] = force_encoding(captures) unless captures.nil? || captures.empty?
      else
        values += params.values.flatten
      end

      catch(:pass) do
        conditions.each { |c| throw :pass if c.bind(self).call == false }
        block ? block[self, values] : yield(self, values)
      end
    rescue
      @env['sinatra.error.params'] = @params
      raise
    ensure
      @params = original if original
    end
100171
function buildTemplatePartial(path) {
  
  var tplDir = app.mvcpath + app.paths.templates;
  var p = path.replace(tplDir, '');
  var pos = p.indexOf('.');
  var ext = p.slice(pos+1);
  var tpl = p.slice(0,pos);

  if (ext in this.enginesByExtension) {
    
    var engine = this.enginesByExtension[ext];
    var func = engine.renderPartial(path);
    
    func.engine = engine;
    func.ext = ext;
    
    this.templates[tpl] = func;
    
  } else {
    
    throw new Error(util.format("Unable to render %s: engine not loaded",  this.relPath(path)));
    
  }
  
}
428462
function(route, args, base) {
            base = base || "";
            args = args || {};
            var url = route;
            url = url.replace("#!/","#").replace("#!", "#").replace("#", "");
            _.map(args, function(value, attr) {
                url = url.replace("\:"+attr, value);
            });
            return base+"#/"+url;
        }
975202
private static function determineStaticPrefix(Route $route, array $tokens): string
    {
        if (!$tokens) {
            return '';
        }

        if ('text' !== $tokens[0][0]) {
            return ($route->hasDefault($tokens[0][3]) || '/' === $tokens[0][1]) ? '' : $tokens[0][1];
        }

        $prefix = $tokens[0][1];

        if (isset($tokens[1][1]) && '/' !== $tokens[1][1] && false === $route->hasDefault($tokens[1][3])) {
            $prefix .= $tokens[1][1];
        }

        return $prefix;
    }
1144548
function fixRoute(route) {
	
	//protect special chars while we replace
	return route.replace(/\s*OR\s*/g,'__OR__').
	replace(/\s*->\s*/g,'__->__').
	replace(/[\s\t\n]+/g,'/').
	replace(/__/g,' ');
}
50281
def add(self, rule, method, target, name=None, static=False):
        '''  '''
        if static:
            depr("Use a backslash to escape ':' in routes.") # 0.9
            rule = rule.replace(':','\\:')

        if rule in self.routes:
            self.routes[rule][method.upper()] = target
        else:
            self.routes[rule] = {method.upper(): target}
            self.rules.append(rule)
            if self.static or self.dynamic: # Clear precompiler cache.
                self.static, self.dynamic = {}, {}
        if name:
            self.named[name] = (rule, None)
145969
private static function format() {

		$routes = static :: getRoutes();

		foreach($routes as $identifier => $route) {

			$url = preg_quote($route -> getUrl(), '/'); 

			//Prepend prefix for url
			if($prefix = $route -> getPrefix()) {
				$url = $prefix['url'] . $url;
			}

			if(preg_match_all('#(\\\/)*\\\{([a-zA-Z0-9_.]+)(\\\\\?)?\\\}#i', $url, $matches)) {
				
				foreach($matches[0] as $index => $match) {

					$match 		= $matches[0][$index];
					$slash 		= $matches[1][$index];
					$type 		= $matches[2][$index];
					$optional 	= $matches[3][$index];
					$where 		= $route -> getWhere();
					$variable 	= '';
					$typefound 	= false;

					if('' !== $slash) {
						$variable .= '\/';
					}

					if(true === is_array($where)) {
						
						foreach($where as $key => $regex) {
							
							if($key === $type) {
								
								$variable .= $regex;
								$typefound = true;
								break;
							}
						}
					}

					if(false === $typefound) {

						if(isset(static :: $types[$type])) {
							$variable .= static :: $types[$type];
						}
						else {
							$variable .= static :: $types['string'];	
						}
					}

					if('' !== $optional) {
						$variable = '('. $variable .')?';
					}
					else {
						$variable = '('. $variable .')';
					}
					
					$url = preg_replace('#' . preg_quote($match, '/') . '#', $variable, $url, 1);
				}
			}

			$route -> setMatch($url);
		}
	}
507027
function Route(pattern, callback, priority, router) {
        var isRegexPattern = isRegExp(pattern),
            patternLexer = router.patternLexer;
        this._router = router;
        this._pattern = pattern;
        this._paramsIds = isRegexPattern? null : patternLexer.getParamIds(pattern);
        this._optionalParamsIds = isRegexPattern? null : patternLexer.getOptionalParamsIds(pattern);
        this._matchRegexp = isRegexPattern? pattern : patternLexer.compilePattern(pattern, router.ignoreCase);
        this.matched = new signals.Signal();
        this.switched = new signals.Signal();
        if (callback) {
            this.matched.add(callback);
        }
        this._priority = priority || 0;
    }
576548
def tokenise(cls, route):
        '''  '''
        match = None
        for match in cls.syntax.finditer(route):
            pre, name, rex = match.groups()
            if pre: yield ('TXT', pre.replace('\\:',':'))
            if rex and name: yield ('VAR', (rex, name))
            elif name: yield ('VAR', (cls.default, name))
            elif rex: yield ('ANON', rex)
        if not match:
            yield ('TXT', route.replace('\\:',':'))
        elif match.end() < len(route):
            yield ('TXT', route[match.end():].replace('\\:',':'))