matchAsPrefix method
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
at that point.
The start
must be non-negative and no greater than string.length
.
final string = 'Dash is a bird';
var regExp = RegExp(r'bird');
var match = regExp.matchAsPrefix(string, 10); // Match found.
regExp = RegExp(r'bird');
match = regExp.matchAsPrefix(string); // null
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;
}