matchesSamePaths method

bool matchesSamePaths(
  1. Pattern other
)

Checks if two patterns will match the exact same set of paths.

That is, the two patterns are exactly the same except that any variables in them may have different variable names.

For example, "~/foo/:bar" and "~/foo/:XYZ" will return true, but compareTo does not return zero for them.

Implementation

bool matchesSamePaths(Pattern other) {
  if (_segments.length != other._segments.length) {
    return false;
  }

  for (var x = 0; x < _segments.length; x++) {
    final s1 = _segments[x];
    final s2 = other._segments[x];

    if (_isVariable(s1)) {
      if (!_isVariable(s2)) {
        return false;
      }
      // Do not care if variable names are different
    } else if (_isOptional(s1)) {
      if (!_isOptional(s2)) {
        return false;
      }
      if (_optionalName(s1) != _optionalName(s2)) {
        return false;
      }
    } else if (s1 == wildcard) {
      if (s2 != wildcard) {
        return false;
      }
    } else {
      // Literal segment
      if (s1 != s2) {
        return false;
      }
    }
  }

  return true;
}