mirror of
https://github.com/chmln/sd
synced 2024-11-25 20:40:22 +00:00
Fix crash on Windows | resolves #37
This commit is contained in:
parent
61d678c1d2
commit
4982a6645c
1 changed files with 11 additions and 8 deletions
19
src/input.rs
19
src/input.rs
|
@ -47,20 +47,20 @@ impl Replacer {
|
|||
match c {
|
||||
'c' => {
|
||||
regex.case_insensitive(false);
|
||||
}
|
||||
},
|
||||
'i' => {
|
||||
regex.case_insensitive(true);
|
||||
}
|
||||
},
|
||||
'm' => {
|
||||
regex.multi_line(true);
|
||||
}
|
||||
},
|
||||
'w' => {
|
||||
regex = regex::bytes::RegexBuilder::new(&format!(
|
||||
"\\b{}\\b",
|
||||
look_for
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -110,6 +110,9 @@ impl Replacer {
|
|||
mmap_target.deref_mut().write_all(&replaced)?;
|
||||
mmap_target.flush()?;
|
||||
|
||||
drop(source);
|
||||
drop(mmap_source);
|
||||
|
||||
target.persist(path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -128,7 +131,7 @@ impl Replacer {
|
|||
handle.write_all(&self.replace(&buffer))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
(Source::Files(paths), true) => {
|
||||
use rayon::prelude::*;
|
||||
|
||||
|
@ -137,7 +140,7 @@ impl Replacer {
|
|||
.map(|p| self.replace_file(p).map_err(Error::log))
|
||||
.collect::<Vec<Result<()>>>();
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
(Source::Files(paths), false) => {
|
||||
let stdout = std::io::stdout();
|
||||
let mut handle = stdout.lock();
|
||||
|
@ -152,7 +155,7 @@ impl Replacer {
|
|||
})
|
||||
.collect::<Result<Vec<()>>>()?;
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue