1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-04 15:07:47 +00:00

refactor/polish ~ fix cargo clippy complaints (use is_empty / is_none)

This commit is contained in:
Roy Ivy III 2019-12-26 11:00:40 -06:00
parent 2931c808b6
commit bb15dcf1b8
22 changed files with 33 additions and 33 deletions

View file

@ -53,7 +53,7 @@ impl FromStr for Range {
Err(inval)
}
}
(Some(n), Some(m)) if n.len() == 0 => {
(Some(n), Some(m)) if n.is_empty() => {
if let Ok(high) = m.parse::<usize>() {
if high > 0 {
Ok(Range { low: 1, high })

View file

@ -259,7 +259,7 @@ fn behaviour(matches: &getopts::Matches) -> Result<Behaviour, i32> {
/// Returns an integer intended as a program return code.
///
fn directory(paths: &[PathBuf], b: Behaviour) -> i32 {
if paths.len() < 1 {
if paths.is_empty() {
println!("{} with -d requires at least one argument.", NAME);
1
} else {

View file

@ -186,7 +186,7 @@ impl Spec {
let file_num = match chars.next() {
Some('0') => {
// Must be all alone without a field specifier.
if let None = chars.next() {
if chars.next().is_none() {
return Spec::Key;
}

View file

@ -159,7 +159,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
}
fn exec(files: &[PathBuf], settings: &Settings) -> i32 {
if files.len() == 0 {
if files.is_empty() {
show_error!(
"missing file operand\nTry '{} --help' for more information.",
NAME
@ -201,7 +201,7 @@ fn exec(files: &[PathBuf], settings: &Settings) -> i32 {
);
return 1;
}
assert!(files.len() != 0);
assert!(!files.is_empty());
match link(&files[0], &files[1], settings) {
Ok(_) => 0,

View file

@ -531,7 +531,7 @@ fn get_file_name(name: &Path, strip: Option<&Path>) -> String {
Some(prefix) => name.strip_prefix(prefix).unwrap_or(name),
None => name,
};
if name.as_os_str().len() == 0 {
if name.as_os_str().is_empty() {
name = Path::new(".");
}
name.to_string_lossy().into_owned()

View file

@ -426,7 +426,7 @@ fn existing_backup_path(path: &PathBuf, suffix: &str) -> PathBuf {
fn is_empty_dir(path: &PathBuf) -> bool {
match fs::read_dir(path) {
Ok(contents) => {
return contents.peekable().peek().is_none();
contents.peekable().peek().is_none()
},
Err(_e) => { false }
}

View file

@ -363,7 +363,7 @@ fn pass_regex(line: &str, re: &regex::Regex) -> bool {
}
fn pass_nonempty(line: &str, _: &regex::Regex) -> bool {
line.len() > 0
!line.is_empty()
}
fn pass_none(_: &str, _: &regex::Regex) -> bool {

View file

@ -353,7 +353,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
let options = parse_options(&matches).unwrap();
if matches.free.len() == 0 {
if matches.free.is_empty() {
handle_stdin(options).unwrap()
} else {
handle_args(&matches.free, options).unwrap()

View file

@ -36,7 +36,7 @@ impl<'b> MultifileReader<'b> {
fn next_file(&mut self) {
// loop retries with subsequent files if err - normally 'loops' once
loop {
if self.ni.len() == 0 {
if self.ni.is_empty() {
self.curr_file = None;
break;
}

View file

@ -73,7 +73,7 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result<CommandLineInputs,
}
}
if input_strings.len() == 0 {
if input_strings.is_empty() {
input_strings.push("-".to_string());
}
Ok(CommandLineInputs::FileNames(input_strings))

View file

@ -188,7 +188,7 @@ fn check_extra(path: &[String]) -> bool {
}
}
// path length
if path.join("/").len() == 0 {
if path.join("/").is_empty() {
writeln!(&mut std::io::stderr(), "empty file name");
return false;
}

View file

@ -60,7 +60,7 @@ fn get_primitive_hex(
Some(pos) => (&str_in[..pos], &str_in[pos + 1..]),
None => (&str_in[..], "0"),
};
if first_segment_raw.len() == 0 {
if first_segment_raw.is_empty() {
first_segment_raw = "0";
}
// convert to string, hexifying if input is in dec.

View file

@ -223,7 +223,7 @@ pub fn get_primitive_dec(
Some(pos) => (&str_in[..pos], &str_in[pos + 1..]),
None => (&str_in[..], "0"),
};
if first_segment_raw.len() == 0 {
if first_segment_raw.is_empty() {
first_segment_raw = "0";
}
// convert to string, de_hexifying if input is in hex.
@ -317,7 +317,7 @@ pub fn primitive_to_str_common(prim: &FormatPrimitive, field: &FormatField) -> S
let decimal_places = field.second_field.unwrap_or(6);
match prim.post_decimal {
Some(ref post_decimal) => {
if post_decimal.len() > 0 && decimal_places > 0 {
if !post_decimal.is_empty() && decimal_places > 0 {
final_str.push('.');
let len_avail = post_decimal.len() as u32;

View file

@ -52,7 +52,7 @@ fn get_provided(str_in_opt: Option<&String>) -> Option<u8> {
for cont in byte_it {
ignored.push(cont);
}
if ignored.len() > 0 {
if !ignored.is_empty() {
warn_char_constant_ign(ignored);
}
second_byte as u8

View file

@ -190,7 +190,7 @@ impl SubParser {
}
match self.min_width_tmp.as_mut() {
Some(x) => {
if (ch == '-' || ch == '*') && x.len() > 0 {
if (ch == '-' || ch == '*') && !x.is_empty() {
err_conv(&self.text_so_far);
}
if ch == '*' {
@ -213,7 +213,7 @@ impl SubParser {
}
match self.second_field_tmp.as_mut() {
Some(x) => {
if ch == '*' && x.len() > 0 {
if ch == '*' && !x.is_empty() {
err_conv(&self.text_so_far);
}
if ch == '*' {
@ -252,7 +252,7 @@ impl SubParser {
}
}
}
if !self.field_char.is_some() {
if self.field_char.is_none() {
err_conv(&self.text_so_far);
}
let field_char_retrieved = self.field_char.unwrap();

View file

@ -201,7 +201,7 @@ impl UnescapedText {
// on non hex or octal escapes is costly
// then we can make it faster/more complex
// with as-necessary draining.
if tmp_str.len() > 0 {
if !tmp_str.is_empty() {
new_vec.extend(tmp_str.bytes());
tmp_str = String::new();
}
@ -228,7 +228,7 @@ impl UnescapedText {
}
}
}
if tmp_str.len() > 0 {
if !tmp_str.is_empty() {
new_vec.extend(tmp_str.bytes());
}
}

View file

@ -189,11 +189,11 @@ pub fn uumain(args: Vec<String>) -> i32 {
Ok(m) => m,
Err(f) => return f,
};
if free.len() < 1 || free.len() > 3 {
if free.is_empty() || free.len() > 3 {
crash!(
1,
"too {} operands.\nTry '{} --help' for more information.",
if free.len() < 1 { "few" } else { "many" },
if free.is_empty() { "few" } else { "many" },
NAME
);
}

View file

@ -276,7 +276,7 @@ pub fn parse_size(mut size_slice: &str) -> Result<u64, ParseSizeErr> {
1024u64
};
let exponent = if size_slice.len() > 0 {
let exponent = if !size_slice.is_empty() {
let mut has_suffix = true;
let exp = match size_slice.chars().last().unwrap_or('_') {
'K' | 'k' => 1u64,

View file

@ -53,7 +53,7 @@ pub fn uumain(_: Vec<String>) -> i32 {
}
fn one(args: &[&[u8]]) -> bool {
args[0].len() > 0
!args[0].is_empty()
}
fn two(args: &[&[u8]], error: &mut bool) -> bool {
@ -212,13 +212,13 @@ enum Precedence {
}
fn parse_expr(mut args: &[&[u8]], error: &mut bool) -> bool {
if args.len() == 0 {
if args.is_empty() {
false
} else {
let hashmap = setup_hashmap();
let lhs = dispatch(&mut args, error);
if args.len() > 0 {
if !args.is_empty() {
parse_expr_helper(&hashmap, &mut args, lhs, Precedence::Unknown, error)
} else {
lhs
@ -237,11 +237,11 @@ fn parse_expr_helper<'a>(
*error = true;
&min_prec
});
while !*error && args.len() > 0 && prec as usize >= min_prec as usize {
while !*error && !args.is_empty() && prec as usize >= min_prec as usize {
let op = args[0];
*args = &(*args)[1..];
let mut rhs = dispatch(args, error);
while args.len() > 0 {
while !args.is_empty() {
let subprec = *hashmap.get(&args[0]).unwrap_or_else(|| {
*error = true;
&min_prec
@ -269,7 +269,7 @@ fn parse_expr_helper<'a>(
Precedence::Paren => unimplemented!(), // TODO: implement parentheses
_ => unreachable!(),
};
if args.len() > 0 {
if !args.is_empty() {
prec = *hashmap.get(&args[0]).unwrap_or_else(|| {
*error = true;
&min_prec

View file

@ -43,7 +43,7 @@ impl<'a> Iterator for Unescape<'a> {
#[inline]
fn next(&mut self) -> Option<Self::Item> {
if self.string.len() == 0 {
if self.string.is_empty() {
return None;
}

View file

@ -190,7 +190,7 @@ fn parse_size(size: &str) -> (u64, TruncateMode) {
};
if slice.chars().last().unwrap().is_alphabetic() {
slice = &slice[..slice.len() - 1];
if slice.len() > 0 && slice.chars().last().unwrap().is_alphabetic() {
if !slice.is_empty() && slice.chars().last().unwrap().is_alphabetic() {
slice = &slice[..slice.len() - 1];
}
}

View file

@ -70,7 +70,7 @@ fn main() {
}
// try first arg as util name.
if args.len() >= 1 {
if !args.is_empty() {
let util = &args[0][..];
match umap.get(util) {