resolve method

bool resolve (String absolute, String relative, List<RoutingResult<T>> out, { String method: 'GET', bool strip: true })

Finds the first Route that matches the given path, with the given method.

Implementation

bool resolve(String absolute, String relative, List<RoutingResult<T>> out,
    {String method = 'GET', bool strip = true}) {
  final cleanRelative =
      strip == false ? relative : stripStraySlashes(relative);
  var scanner = new SpanScanner(cleanRelative);

  bool crawl(Router<T> r) {
    bool success = false;

    for (var route in r.routes) {
      int pos = scanner.position;

      if (route is SymlinkRoute<T>) {
        if (route.parser.parse(scanner).successful) {
          var s = crawl(route.router);
          if (s) success = true;
        }

        scanner.position = pos;
      } else if (route.method == '*' || route.method == method) {
        var parseResult = route.parser.parse(scanner);

        if (parseResult.successful && scanner.isDone) {
          var result = new RoutingResult<T>(
              parseResult: parseResult,
              params: parseResult.value.params,
              shallowRoute: route,
              shallowRouter: this,
              tail: (parseResult.value.tail ?? '') + scanner.rest);
          out.add(result);
          success = true;
        }

        scanner.position = pos;
      }
    }

    return success;
  }

  return crawl(this);
}