/*
If path is omitted the name of the route is used as the path
If method is ommitted, GET is used
195580
function expandDefinition(app, name, route) {
  if (!route)
    return null;
  var label = niceName(name);
  if (typeof route === 'function') {
    return {
      app: app,
      get: [route],
      label: label
    }
  } else if (Array.isArray(route)) {
    var path = undefined, funcs;
    if (typeof route[0] !== 'string') {
      funcs = route;
    } else {
      path = route[0];
      funcs = route.slice(1);
    }
    return {
      app: app,
      path: path,
      get: funcs,
      label: label
    }
  } else if (route.route) { //nested routes
    debugger; //XXX
  } else {
    var def = {
      app: app,
      path: route.path,
      label: route.label || label
    };
    var found = false;
    for (var key in route) {
      if (key == "path" || key == 'app' || !app[key])
        continue;
      def[key] = (!route[key] || Array.isArray(route[key])) ? route[key] : [route[key]];
      found = true;
    }
    if (!found) {
      def.pathonly = true;
      if (typeof route.path === 'undefined')
        def.path = name
    }
    return def;
  }
}
1282810
function(path) {
    var p = path || this.path(); 
    var pp = (!p || p == "/")? null : p.substring(0, p.lastIndexOf("/"));
    return (pp=="")? "/" : pp;
  }
1121910
function(uri) {
        var original_segments = window.location.pathname.split('/');
        var route_segments = uri.split('/');
        var route_length = route_segments.length;
        var params = {};
        for (var i = 1; i < route_length; i++) {
            if (route_segments[i].indexOf('{') !== -1) {
                var name = route_segments[i].substr(1, route_segments[i].length-2);
                params[name] = original_segments[i];
            }
        }
        return params;
    }
502464
private boolean matchesPath(String routePath, String pathToMatch) {
        routePath = PathKit.VAR_REGEXP_PATTERN.matcher(routePath).replaceAll(PathKit.VAR_REPLACE);
        return pathToMatch.matches("(?i)" + routePath);
    }
657758
@Override
  public PathImpl getPath(String name)
  {
    if (name.startsWith("/"))
      return _path.lookup("." + name);
    else
      return _path.lookup(name);
  }
532984
function routePath (route) {
  if (!route) return ''
  return route.path || (route.regexp && route.regexp.source) || ''
}
445055
def method_missing(method, *args)
      if verb = method.to_s.match(/\Ahttp_(get|post|put|delete|head)\z/)

        orig_uri, @uri = @uri, @uri.dup
        begin
          path, query = args[0].split('?', 2)
          @uri.path = "#{path}.#{@format.extension}#{'?' << query if query}" # Should be the form of /resources
          run_verb(verb.to_s.split('_').last, args[1])
        ensure
          @uri = orig_uri
        end
      end
    end
487295
function replace(pathname) {
        if (typeof routesMap === 'function') {
            return routesMap(pathname) || pathname
        }

        let matched = false
        return pathname
            .split('/')
            .map(chunk => {
                // console.log(chunk);
                if (!matched) {
                    if (routesMap[chunk]) {
                        matched = true
                    }
                    return typeof routesMap[chunk] === 'string' ? routesMap[chunk] : chunk
                }
                else {
                    return chunk
                }
            })
            .join('/')
            .replace(/\/\//, '/')
    }
1067548
def for(path, *args)
      arg = args[0]
      log.debug "Adding route, path: #{path}, args: #{args.inspect}"

      match = get_regex_for_route(path, arg)
      hash = get_to_hash(arg)
      route_info = {:regex => match[:regex], :args => arg, :vars => match[:vars], :hash => hash}
      
      # Add the HTTP methods for this route if they exist in options
      route_info[:methods] = arg[:methods] if not arg.nil? and arg.has_key? :methods
      
      self.routes.push(route_info)
    end
1105365
public Response get(String path, Map<String, String> params) throws IOException, RESTException {
        return get(path, params, null);
    }
919172
function routeObjToRouteName(route, path) {
    var name = route.controllerAs;

    var controller = route.controller;
    if (!name && controller) {
      if (angular.isArray(controller)) {
        controller = controller[controller.length - 1];
      }
      name = controller.name;
    }

    if (!name) {
      var segments = path.split('/');
      name = segments[segments.length - 1];
    }

    if (name) {
      name = name + 'AutoCmp';
    }

    return name;
  }
1364050
function isActive(_ref, indexOnly, currentLocation, routes, params) {
  var pathname = _ref.pathname;
  var query = _ref.query;

  if (currentLocation == null) return false;

  // TODO: This is a bit ugly. It keeps around support for treating pathnames
  // without preceding slashes as absolute paths, but possibly also works
  // around the same quirks with basenames as in matchRoutes.
  if (pathname.charAt(0) !== '/') {
    pathname = '/' + pathname;
  }

  if (!pathIsActive(pathname, currentLocation.pathname)) {
    // The path check is necessary and sufficient for indexOnly, but otherwise
    // we still need to check the routes.
    if (indexOnly || !routeIsActive(pathname, routes, params)) {
      return false;
    }
  }

  return queryIsActive(query, currentLocation.query);
}
800415
static <T> T get(Map<String, Object> olm, String path, T def) {
        Object ret = def;
        try {
            String[] parts = tokenizePath(path);
            Object o = olm;
            for (int i = 0; i < parts.length; i++) {
                int[] j = getNumber(parts[i]);
                String name = getLocalName(parts[i]);
                o = ((Map) o).get(name);
                if (j != null) {
                    for (int k = 0; k < j.length; k++) {
                        o = ((List) o).get(j[k]);
                    }
                }
            }
            if (o != null)
                ret = o;
            else
                ret = def;
        } catch (Throwable e) {
        }
        return (T) ret;
    }
1081932
function(context) {

            // Check path
            var path = context.request.urlInfo.pathname;

            if (path.indexOf(this.$.path) === 0) {
                // path matches
                if (this.$.route !== null) {
                    return (new RegExp(this.$.route, "i")).test(path);
                }

                return true;
            }

            return false;
        }
14936
public static String ensureAbsolutePath(String path, String paramName) {
        requireNonNull(path, paramName);
        if (path.isEmpty() || path.charAt(0) != '/') {
            throw new IllegalArgumentException(paramName + ": " + path + " (expected: an absolute path)");
        }
        return path;
    }
796518
function getRoute(route) {
                for (var key in settings.routes) {
                    if (key === route) {
                        return settings.routes[key];
                    }
                }
            }
86255
function matchRoute(route, path) {

  if (route.pattern === undefined && route.path !== undefined) {
    var routePattern;

    if (route.path instanceof RegExp) {
      routePattern = route.path;
    } else {
      var routePath = normalize(route.path);
      routePattern = route.children.length > 0 ? routePath + '*' : routePath;
    }

    Object.defineProperty(route, 'pattern', {
      enumerable: false,
      value: pattern.newPattern(routePattern)
    });
  }

  if (route.pattern) {
    var match = route.pattern.match(path);

    if (match) {
      if (route.pattern.isRegex) {
        match = {_: match};
      }

      if (!match._ || match._[0] === '/' || match._[0] === '') {
        delete match._;
      }
    }

    return match;

  } else {
    return path === '/' || path === '' ? {} : {_: [path]};
  }
}