use std::path::MAIN_SEPARATOR;
use strfmt;
use dev_prefix::*;
use types::*;
lazy_static! {
static ref MAIN_SEPARATOR_STR: String = MAIN_SEPARATOR.to_string();
}
pub fn do_strfmt(s: &str, vars: &HashMap<String, String>, fpath: &Path) -> Result<String> {
strfmt::strfmt(s, vars).chain_err(|| {
format!("ERROR at {}: {}", fpath.display(), s.to_string())
})
}
pub fn get_path_str(path: &Path) -> Result<&str> {
match path.to_str() {
Some(p) => Ok(p),
None => Err(
ErrorKind::InvalidUnicode(format!("{}", path.display())).into(),
),
}
}
pub fn convert_path_str(path: &str) -> String {
path.replace("/", &MAIN_SEPARATOR_STR)
}
#[test]
#[cfg(windows)]
fn test_convert_windows() {
let expected = "this\\is\\a\\windows\\path";
assert_eq!(expected, convert_path_str("this/is/a/windows/path"));
}
#[test]
#[cfg(not(windows))]
fn test_convert_posix() {
let expected = "this/is/a/unix/path";
assert_eq!(expected, convert_path_str(expected));
}