matchAsPrefix method

Match matchAsPrefix (
  1. String path,
  2. [int start = 0]

Match this pattern against the start of string.

If start is provided, it must be an integer in the range 0 .. string.length. In that case, this patten is tested against the string at the start position. That is, a Match is returned if the pattern can match a part of the string starting from position start. Returns null if the pattern doesn't match.


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;