1use std::ffi::OsStr;
2
3pub fn to_posix_path(path: impl AsRef<str>) -> String {
7 path.as_ref().replace('\\', "/")
8}
9
10pub fn to_win32_path(path: impl AsRef<str>) -> String {
14 path.as_ref().replace('/', "\\")
15}
16
17pub fn to_platform_path(path: impl AsRef<str>) -> String {
22 path.as_ref()
23 .replace(['/', '\\'], std::path::MAIN_SEPARATOR_STR)
24}
25
26pub fn escape_data(data: impl AsRef<str>) -> String {
27 data.as_ref()
28 .replace('%', "%25")
29 .replace('\r', "%0D")
30 .replace('\n', "%0A")
31}
32
33pub fn escape_property(prop: impl AsRef<str>) -> String {
34 prop.as_ref()
35 .replace('%', "%25")
36 .replace('\r', "%0D")
37 .replace('\n', "%0A")
38 .replace(':', "%3A")
39 .replace(',', "%2C")
40}
41
42pub fn not_empty<T>(value: T) -> Option<T>
47where
48 T: AsRef<OsStr>,
49{
50 if value.as_ref().is_empty() {
51 None
52 } else {
53 Some(value)
54 }
55}