parseMatcher static method

PathMatcher parseMatcher(
  1. String path
)

Creates a matcher for the specified path matcher definition.

Implementation

static PathMatcher parseMatcher(String path) {
  List<PathMatcherFragment> fragments = [];
  var sanitized = sanitizePath(path);
  var spliced = splitPath(sanitized);
  for (var element in spliced) {
    // Check if the fragment matches the variable syntax
    var variableMatches = variableRegex.allMatches(element);
    if (variableMatches.isEmpty) {
      // Not a variable so we expected an exact match
      fragments.add(FixedPathMatcherFragment(element));
    } else {
      // Fragment is a valid template definition
      var variableName = variableMatches.first.group(1).toString();
      fragments.add(VariablePathMatcherFragment(variableName));
    }
  }
  return PathMatcher(sanitized, fragments);
}