1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Replace trim_{left,right} with trim_{start,end} and co. (using Rerast)

This commit is contained in:
Alex Lyon 2019-04-28 03:49:18 -07:00
parent c7d115b1ad
commit 179de609b5
8 changed files with 29 additions and 11 deletions

18
util/rewrite_rules.rs Normal file
View file

@ -0,0 +1,18 @@
//! Rules to update the codebase using Rerast
/// Converts try!() to ?
fn try_to_question_mark<T, E, X: From<E>>(r: Result<T, E>) -> Result<T, X> {
replace!(try!(r) => r?);
unreachable!()
}
fn trim_left_to_start(s: &str) {
replace!(s.trim_left() => s.trim_start());
replace!(s.trim_right() => s.trim_end());
}
fn trim_left_matches_to_start<P: FnMut(char) -> bool>(s: &str, inner: P) {
replace!(s.trim_left_matches(inner) => s.trim_start_matches(inner));
replace!(s.trim_right_matches(inner) => s.trim_end_matches(inner));
}