Skip to content
Myr

Rewrite replace_path_separator function

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by sharkdp · parent 2ea77e7 · Browse files · 2 files+10 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−11 removed

  • other:+10 added−11 removed

2 files+10 added−11 removed

modified:src/filesystem.rs+2 added-7 removed
91 unmodified lines
92 }93 iter.as_path()94}9596pub fn replace_path_separator<'a>(path_separator: &Option<String>, path: &mut Cow<'a, str>) {97 match &path_separator {98 None => {}99 Some(sep) => {100 *path.to_mut() = path.replace(std::path::MAIN_SEPARATOR, &sep);101 }102 }96pub fn replace_path_separator<'a>(path: &str, new_path_separator: &str) -> String {97 path.replace(std::path::MAIN_SEPARATOR, &new_path_separator)98}99100#[cfg(test)]101mod tests {
17 unmodified lines
modified:src/output.rs+8 added-4 removed
51 unmodified lines
52 .map(Style::to_ansi_term_style)53 .unwrap_or(default_style);5455 let mut path_string = component.to_string_lossy();56 replace_path_separator(&config.path_separator, &mut path_string);56 if let Some(ref separator) = config.path_separator {57 *path_string.to_mut() = replace_path_separator(&path_string, &separator);58 }59 write!(stdout, "{}", style.paint(path_string))?;6061 // TODO: can we move this out of the if-statement? Why do we call it that often?62 if wants_to_quit.load(Ordering::Relaxed) {
16 unmodified lines
79 config: &Options,80) -> io::Result<()> {81 let separator = if config.null_separator { "\0" } else { "\n" };8281 let mut path_str = path.to_string_lossy();82 replace_path_separator(&config.path_separator, &mut path_str);83 write!(stdout, "{}{}", path_str, separator)83 let mut path_string = path.to_string_lossy();84 if let Some(ref separator) = config.path_separator {85 *path_string.to_mut() = replace_path_separator(&path_string, &separator);86 }87 write!(stdout, "{}{}", path_string, separator)88}