matchRoute function
Matches path against patterns, returning the first match. Patterns use
:name segments for parameters. Pure and DOM-free.
Implementation
RouteMatch matchRoute(List<String> patterns, String path) {
final pathSegs = _segments(path);
for (final pattern in patterns) {
final patSegs = _segments(pattern);
if (patSegs.length != pathSegs.length) continue;
final params = <String, String>{};
var ok = true;
for (var i = 0; i < patSegs.length; i++) {
final p = patSegs[i];
final v = pathSegs[i];
if (p.startsWith(':')) {
params[p.substring(1)] = Uri.decodeComponent(v);
} else if (p != v) {
ok = false;
break;
}
}
if (ok) return RouteMatch(pattern, path, params);
}
return RouteMatch('', path);
}