1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::path;
use std::fmt;
pub fn normalize<P: AsRef<path::Path>>(inpath: &P) -> path::PathBuf where P: fmt::Debug {
let mut outpath = path::PathBuf::new();
for component in inpath.as_ref().components() {
match component {
path::Component::CurDir => {},
path::Component::ParentDir => {
outpath.pop();
},
path::Component::RootDir => {
outpath.push(component);
},
path::Component::Prefix(_) => {
outpath.push(component);
},
path::Component::Normal(_) => {
outpath.push(component);
}
}
}
outpath
}