use std::path::{Component, Path, PathBuf};
pub fn normalized_path(path: &Path) -> PathBuf {
let mut result: PathBuf = PathBuf::new();
for component in path.components() {
match component {
Component::Prefix(_) | Component::RootDir => {
result.push(component.as_os_str());
}
Component::CurDir => {}
Component::ParentDir => {
let at_root: bool = result.parent().is_none();
if !at_root && result.file_name().is_some() {
result.pop();
}
}
Component::Normal(name) => {
result.push(name);
}
}
}
return result;
}
#[cfg(test)]
#[path = "lexical_path_tests.rs"]
mod tests;