in lib/src/parsed_path.dart [100:144]
void normalize({bool canonicalize = false}) {
// Handle '.', '..', and empty parts.
var leadingDoubles = 0;
final newParts = <String>[];
for (var part in parts) {
if (part == '.' || part == '') {
// Do nothing. Ignore it.
} else if (part == '..') {
// Pop the last part off.
if (newParts.isNotEmpty) {
newParts.removeLast();
} else {
// Backed out past the beginning, so preserve the "..".
leadingDoubles++;
}
} else {
newParts.add(canonicalize ? style.canonicalizePart(part) : part);
}
}
// A relative path can back out from the start directory.
if (!isAbsolute) {
newParts.insertAll(0, List.filled(leadingDoubles, '..'));
}
// If we collapsed down to nothing, do ".".
if (newParts.isEmpty && !isAbsolute) {
newParts.add('.');
}
// Canonicalize separators.
parts = newParts;
separators =
List.filled(newParts.length + 1, style.separator, growable: true);
if (!isAbsolute || newParts.isEmpty || !style.needsSeparator(root!)) {
separators[0] = '';
}
// Normalize the Windows root if needed.
if (root != null && style == Style.windows) {
if (canonicalize) root = root!.toLowerCase();
root = root!.replaceAll('/', '\\');
}
removeTrailingSeparators();
}