Sha256: 254e28f4b964ca6fb06d05d233467bd11d86f90539f6f1c7a86a4f2490fc6c26
Contents?: true
Size: 632 Bytes
Versions: 3
Compression:
Stored size: 632 Bytes
Contents
use std::borrow::Cow; use dirname::dirname; use path_parsing::{SEP, contains_sep}; use std::path::MAIN_SEPARATOR; pub fn prepend_prefix<'a>(prefix: &'a str, relpath: &str) -> Cow<'a, str> { if relpath.is_empty() { dirname(prefix).into() } else if contains_sep(prefix.as_bytes()) { let prefix_dirname = dirname(prefix); match prefix_dirname.as_bytes().last() { None => relpath.to_string().into(), Some(&SEP) => format!("{}{}", prefix_dirname, relpath).into(), _ => format!("{}{}{}", prefix_dirname, MAIN_SEPARATOR, relpath).into() } } else { format!("{}{}", prefix, relpath).into() } }
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
faster_path-0.3.10 | src/prepend_prefix.rs |
faster_path-0.3.9 | src/prepend_prefix.rs |
faster_path-0.3.8 | src/prepend_prefix.rs |