Expand description
Filename sanitizer.
Supported OS:
- Windows
- Linux (unix)
- MAC
Given a filename, escape the filename so that it is allowed by the OS.
The main functions of this crate are escape_str
and replace_escape
which will take string as input, and return modified version that can be
used as filename:
use filesan::{escape_str, Mode};
// Unix support
assert_eq!(
escape_str("\x00hello/the_re.txt:.", '_', Mode::UNIX),
"_00hello_2Fthe_5Fre.txt:."
);
// Windows support
assert_eq!(
escape_str("\x00hello/the_re.txt:.", '_', Mode::WINDOWS),
"_00hello_2Fthe_5Fre.txt_3A_2E"
);
// MACOS support
assert_eq!(
escape_str("\x00hello/the_re.txt:.", '_', Mode::MAC),
"_00hello_2Fthe_5Fre.txt_3A."
);
You can use Mode::SYSTEM
to get your current target system. See
documentation of escape_str
and replace_escape
for more info.
Structs§
- Mode
- Escape flags for different systems. See documentation of
crate::escape_str
for more info.
Constants§
- SYSTEM_
RESERVED - Reserved filenames on the current target system (unix).
- UNIX_
RESERVED - Reserved filenames on unix.
- WINDOWS_
RESERVED - Reserved filenames on windows.
Functions§
- allowed
- Checks if the given char is allowed in path on the given systems.
- escape_
str - Escape the given string so that it may be used as valid path on the given systems.
- replace_
escape - Escape the given string so that it may be used as valid path on the given systems.