in lib/src/context.dart [824:874]
_PathDirection _pathDirection(String path, int index) {
var depth = 0;
var reachedRoot = false;
var i = index;
while (i < path.length) {
// Ignore initial separators or doubled separators.
while (i < path.length && style.isSeparator(path.codeUnitAt(i))) {
i++;
}
// If we're at the end, stop.
if (i == path.length) break;
// Move through the path component to the next separator.
final start = i;
while (i < path.length && !style.isSeparator(path.codeUnitAt(i))) {
i++;
}
// See if the path component is ".", "..", or a name.
if (i - start == 1 && path.codeUnitAt(start) == chars.period) {
// Don't change the depth.
} else if (i - start == 2 &&
path.codeUnitAt(start) == chars.period &&
path.codeUnitAt(start + 1) == chars.period) {
// ".." backs out a directory.
depth--;
// If we work back beyond the root, stop.
if (depth < 0) break;
// Record that we reached the root so we don't return
// [_PathDirection.belowRoot].
if (depth == 0) reachedRoot = true;
} else {
// Step inside a directory.
depth++;
}
// If we're at the end, stop.
if (i == path.length) break;
// Move past the separator.
i++;
}
if (depth < 0) return _PathDirection.aboveRoot;
if (depth == 0) return _PathDirection.atRoot;
if (reachedRoot) return _PathDirection.reachesRoot;
return _PathDirection.belowRoot;
}