Function mmrbi::path::cleanup

source · []
pub fn cleanup(path: impl AsRef<Path>) -> PathBuf
Expand description

Cleanup/simplify path as much as possible

Examples

assert_eq!(cleanup("a/b"),                      Path::new("a/b"));
assert_eq!(cleanup("a/b/.."),                   Path::new("a"));
assert_eq!(cleanup("a/b/../.."),                Path::new("."));
assert_eq!(cleanup("a/b/../../.."),             Path::new(".."));
assert_eq!(cleanup("a/b/../../../.."),          Path::new("../.."));

assert_eq!(cleanup("../../a/b"),                Path::new("../../a/b"));
assert_eq!(cleanup("../../a/b/.."),             Path::new("../../a"));
assert_eq!(cleanup("../../a/b/../.."),          Path::new("../.."));
assert_eq!(cleanup("../../a/b/../../.."),       Path::new("../../.."));
assert_eq!(cleanup("../../a/b/../../../.."),    Path::new("../../../.."));

if cfg!(windows) {
    assert_eq!(cleanup(r"C:\foo\bar"),          Path::new(r"C:\foo\bar"));
    assert_eq!(cleanup(r"\\?\C:\foo\bar"),      Path::new(r"C:\foo\bar"));
}