mirror of
https://github.com/uutils/coreutils
synced 2024-07-22 02:14:38 +00:00
Replace trim_{left,right} with trim_{start,end} and co. (using Rerast)
This commit is contained in:
parent
c7d115b1ad
commit
179de609b5
|
@ -520,7 +520,7 @@ impl<'a> WordSplit<'a> {
|
|||
impl<'a> WordSplit<'a> {
|
||||
fn new<'b>(opts: &'b FmtOptions, string: &'b str) -> WordSplit<'b> {
|
||||
// wordsplits *must* start at a non-whitespace character
|
||||
let trim_string = string.trim_left();
|
||||
let trim_string = string.trim_start();
|
||||
WordSplit {
|
||||
opts,
|
||||
string: trim_string,
|
||||
|
|
|
@ -94,7 +94,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: String) {
|
|||
match file.read_line(&mut line) {
|
||||
Ok(0) => break,
|
||||
Ok(_) => {
|
||||
output.push_str(line.trim_right());
|
||||
output.push_str(line.trim_end());
|
||||
output.push_str(&delimiters[delim_count % delimiters.len()]);
|
||||
}
|
||||
Err(e) => crash!(1, "{}", e.to_string()),
|
||||
|
@ -118,7 +118,7 @@ fn paste(filenames: Vec<String>, serial: bool, delimiters: String) {
|
|||
eof[i] = true;
|
||||
eof_count += 1;
|
||||
}
|
||||
Ok(_) => output.push_str(line.trim_right()),
|
||||
Ok(_) => output.push_str(line.trim_end()),
|
||||
Err(e) => crash!(1, "{}", e.to_string()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,7 +416,7 @@ fn format_tex_line(config: &Config, word_ref: &WordRef, line: &str, reference: &
|
|||
output.push_str(&format!("\\{} ", config.macro_name));
|
||||
let all_before = if config.input_ref {
|
||||
let before = &line[0..word_ref.position];
|
||||
adjust_tex_str(before.trim().trim_left_matches(reference))
|
||||
adjust_tex_str(before.trim().trim_start_matches(reference))
|
||||
} else {
|
||||
adjust_tex_str(&line[0..word_ref.position])
|
||||
};
|
||||
|
@ -447,7 +447,7 @@ fn format_roff_line(config: &Config, word_ref: &WordRef, line: &str, reference:
|
|||
output.push_str(&format!(".{}", config.macro_name));
|
||||
let all_before = if config.input_ref {
|
||||
let before = &line[0..word_ref.position];
|
||||
adjust_roff_str(before.trim().trim_left_matches(reference))
|
||||
adjust_roff_str(before.trim().trim_start_matches(reference))
|
||||
} else {
|
||||
adjust_roff_str(&line[0..word_ref.position])
|
||||
};
|
||||
|
|
|
@ -93,8 +93,8 @@ fn print_usage(opts: &Options) {
|
|||
}
|
||||
|
||||
fn parse_size(size: &str) -> Option<u64> {
|
||||
let ext = size.trim_left_matches(|c: char| c.is_digit(10));
|
||||
let num = size.trim_right_matches(|c: char| c.is_alphabetic());
|
||||
let ext = size.trim_start_matches(|c: char| c.is_digit(10));
|
||||
let num = size.trim_end_matches(|c: char| c.is_alphabetic());
|
||||
let mut recovered = num.to_owned();
|
||||
recovered.push_str(ext);
|
||||
if recovered != size {
|
||||
|
|
2
src/tsort/tsort.rs
Executable file → Normal file
2
src/tsort/tsort.rs
Executable file → Normal file
|
@ -79,7 +79,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
let mut line = String::new();
|
||||
match reader.read_line(&mut line) {
|
||||
Ok(_) => {
|
||||
let tokens: Vec<String> = line.trim_right()
|
||||
let tokens: Vec<String> = line.trim_end()
|
||||
.split_whitespace()
|
||||
.map(|s| s.to_owned())
|
||||
.collect();
|
||||
|
|
|
@ -122,7 +122,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
output.push_str(HOST_OS);
|
||||
output.push_str(" ");
|
||||
}
|
||||
println!("{}", output.trim_right());
|
||||
println!("{}", output.trim_end());
|
||||
|
||||
0
|
||||
}
|
||||
|
|
|
@ -110,8 +110,8 @@ impl CmdResult {
|
|||
/// stderr_only is a better choice unless stdout may or will be non-empty
|
||||
pub fn stderr_is<T: AsRef<str>>(&self, msg: T) -> Box<&CmdResult> {
|
||||
assert_eq!(
|
||||
String::from(msg.as_ref()).trim_right(),
|
||||
self.stderr.trim_right()
|
||||
String::from(msg.as_ref()).trim_end(),
|
||||
self.stderr.trim_end()
|
||||
);
|
||||
Box::new(self)
|
||||
}
|
||||
|
|
18
util/rewrite_rules.rs
Normal file
18
util/rewrite_rules.rs
Normal 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));
|
||||
}
|
||||
|
Loading…
Reference in a new issue