diff options
Diffstat (limited to 'utils/string_proc/src/simple_processer.rs')
| -rw-r--r-- | utils/string_proc/src/simple_processer.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/utils/string_proc/src/simple_processer.rs b/utils/string_proc/src/simple_processer.rs new file mode 100644 index 0000000..2de5dfc --- /dev/null +++ b/utils/string_proc/src/simple_processer.rs @@ -0,0 +1,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() +} |
