summaryrefslogtreecommitdiff
path: root/utils/string_proc/src/simple_processer.rs
blob: 2de5dfcc62102fb5ec26fd44fa35a7721dba8242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/// Sanitizes a file path by replacing special characters with underscores.
///
/// This function takes a file path as input and returns a sanitized version
/// where characters that are not allowed in file paths (such as path separators
/// and other reserved characters) are replaced with underscores.
pub fn sanitize_file_path<P: AsRef<str>>(path: P) -> String {
    let path_str = path.as_ref();
    path_str
        .chars()
        .map(|c| match c {
            '/' | '\\' | ':' | '*' | '?' | '"' | '<' | '>' | '|' => '_',
            _ => c,
        })
        .collect()
}