Implement escape_device_names function

Prefix generated path components using the existing device classifier, after filtering and suffix construction.
This commit is contained in:
Mex authored and GitHub committed 2026-11-15 15:59:34 +01:00
1 parent 8244acce2d
commit af87503d04
1 file changed
+6
@@ -345,6 +345,12 @@ fn device_name(n: &str) -> bool {
&& stem.chars().last().is_some_and(|c| c.is_ascii_digit() || matches!(c, '¹' | '²' | '³')))
}
/// Prefix Windows device-name components of a generated export path with `_`.
/// Apply after character filtering and suffix construction, so a safe suffix stays unchanged.
pub fn escape_device_names(path: &str) -> String {
path.split('/').map(|name| if device_name(name) { format!("_{name}") } else { name.to_string() }).collect::<Vec<_>>().join("/")
}
thread_local! {
static ROOTS: RefCell<Option<Arc<Roots>>> = const { RefCell::new(None) };
}