Skip to main content

xml_disassembler/utils/
path.rs

1//! Path normalization for cross-platform consistency.
2
3/// Normalize a path to Unix style (forward slashes).
4/// Strips Windows extended path prefix `\\?\` if present so file operations
5/// behave consistently across platforms.
6pub fn normalize_path_unix(path: &str) -> String {
7    let s = path.trim_start_matches(r"\\?\");
8    s.replace('\\', "/")
9}
10
11#[cfg(test)]
12mod tests {
13    use super::*;
14
15    #[test]
16    fn leaves_unix_paths_unchanged() {
17        assert_eq!(normalize_path_unix("foo/bar/baz"), "foo/bar/baz");
18    }
19
20    #[test]
21    fn converts_backslashes_to_forward() {
22        assert_eq!(normalize_path_unix(r"foo\bar\baz"), "foo/bar/baz");
23    }
24
25    #[test]
26    fn strips_windows_extended_prefix() {
27        assert_eq!(
28            normalize_path_unix(r"\\?\C:\Users\file.xml"),
29            "C:/Users/file.xml"
30        );
31    }
32}