use std::ffi::OsStr;
pub fn to_posix_path(path: impl AsRef<str>) -> String {
path.as_ref().replace('\\', "/")
}
pub fn to_win32_path(path: impl AsRef<str>) -> String {
path.as_ref().replace('/', "\\")
}
pub fn to_platform_path(path: impl AsRef<str>) -> String {
path.as_ref()
.replace(['/', '\\'], std::path::MAIN_SEPARATOR_STR)
}
pub fn escape_data(data: impl AsRef<str>) -> String {
data.as_ref()
.replace('%', "%25")
.replace('\r', "%0D")
.replace('\n', "%0A")
}
pub fn escape_property(prop: impl AsRef<str>) -> String {
prop.as_ref()
.replace('%', "%25")
.replace('\r', "%0D")
.replace('\n', "%0A")
.replace(':', "%3A")
.replace(',', "%2C")
}
pub fn not_empty<T>(value: T) -> Option<T>
where
T: AsRef<OsStr>,
{
if value.as_ref().is_empty() {
None
} else {
Some(value)
}
}