normalize method

String normalize(
  1. String path
)

Normalizes path, simplifying it by handling .., and ., and removing redundant path separators whenever possible.

Note that this is not guaranteed to return the same result for two equivalent input paths. For that, see canonicalize. Or, if you're using paths as map keys use equals and hash as the key callbacks.

context.normalize('path/./to/..//file.text'); // -> 'path/file.txt'

Implementation

String normalize(String path) {
  if (!_needsNormalization(path)) return path;

  final parsed = _parse(path);
  parsed.normalize();
  return parsed.toString();
}