zip/path.rs
1//! Path manipulation utilities
2
3use std::{
4 ffi::OsStr,
5 path::{Component, Path},
6};
7
8/// Simplify a path by removing the prefix and parent directories and only return normal components
9pub(crate) fn simplified_components(input: &Path) -> Option<Vec<&OsStr>> {
10 let mut out = Vec::new();
11 for component in input.components() {
12 match component {
13 Component::Prefix(_) | Component::RootDir => return None,
14 Component::ParentDir => {
15 out.pop()?;
16 }
17 Component::Normal(_) => out.push(component.as_os_str()),
18 Component::CurDir => (),
19 }
20 }
21 Some(out)
22}