couldCanonicalize method
Without accessing the filesystem, returns whether or not passing url
to
canonicalize could possibly return canonicalUrl
.
This is expected to be very efficient, and subclasses are allowed to
return false positives if it would be inefficient to determine whether
url
would actually resolve to canonicalUrl
. Subclasses are not allowed
to return false negatives.
Implementation
bool couldCanonicalize(Uri url, Uri canonicalUrl) {
if (url.scheme != 'file' && url.scheme != '') return false;
if (canonicalUrl.scheme != 'file') return false;
var basename = p.url.basename(url.path);
var canonicalBasename = p.url.basename(canonicalUrl.path);
if (!basename.startsWith("_") && canonicalBasename.startsWith("_")) {
canonicalBasename = canonicalBasename.substring(1);
}
return basename == canonicalBasename ||
basename == p.url.withoutExtension(canonicalBasename);
}