matchAsPrefix method Null safety

  1. @override
Match? matchAsPrefix(
  1. String path,
  2. [int start = 0]
)
override

Matches this pattern against the start of string.

Returns a match if the pattern matches a substring of string starting at start, and null if the pattern doesn't match a that point.

The start must be non-negative and no greater than string.length.

Implementation

@override
Match? matchAsPrefix(String path, [int start = 0]) {
  // Globs are like anchored RegExps in that they only match entire paths, so
  // if the match starts anywhere after the first character it can't succeed.
  if (start != 0) return null;

  if (_patternCanMatchAbsolute &&
      (_contextIsAbsolute || context.isAbsolute(path))) {
    var absolutePath = context.normalize(context.absolute(path));
    if (_ast.matches(toPosixPath(context, absolutePath))) {
      return GlobMatch(path, this);
    }
  }

  if (_patternCanMatchRelative) {
    var relativePath = context.relative(path);
    if (_ast.matches(toPosixPath(context, relativePath))) {
      return GlobMatch(path, this);
    }
  }

  return null;
}