mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
all: clippy fixes
This commit is contained in:
parent
8891571e9a
commit
896bbec760
16 changed files with 48 additions and 44 deletions
|
@ -106,7 +106,7 @@ pub fn uu_app<'a>() -> Command<'a> {
|
|||
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||
for (i, arg) in args.iter().enumerate() {
|
||||
let slice = &arg;
|
||||
if slice.starts_with('-') && slice.chars().nth(1).map_or(false, |c| c.is_digit(10)) {
|
||||
if slice.starts_with('-') && slice.chars().nth(1).map_or(false, |c| c.is_ascii_digit()) {
|
||||
let mut v = args.to_vec();
|
||||
v.remove(i);
|
||||
return (v, Some(slice[1..].to_owned()));
|
||||
|
|
|
@ -20,7 +20,7 @@ pub fn parse_obsolete(src: &str) -> Option<Result<impl Iterator<Item = OsString>
|
|||
let mut has_num = false;
|
||||
let mut last_char = 0 as char;
|
||||
for (n, c) in &mut chars {
|
||||
if c.is_digit(10) {
|
||||
if c.is_ascii_digit() {
|
||||
has_num = true;
|
||||
num_end = n;
|
||||
} else {
|
||||
|
|
|
@ -28,7 +28,7 @@ use std::{
|
|||
cmp::Reverse,
|
||||
error::Error,
|
||||
ffi::{OsStr, OsString},
|
||||
fmt::Display,
|
||||
fmt::{Display, Write as FmtWrite},
|
||||
fs::{self, DirEntry, FileType, Metadata, ReadDir},
|
||||
io::{stdout, BufWriter, ErrorKind, Stdout, Write},
|
||||
path::{Path, PathBuf},
|
||||
|
@ -1825,7 +1825,7 @@ fn display_additional_leading_info(
|
|||
} else {
|
||||
"?".to_owned()
|
||||
};
|
||||
result.push_str(&format!("{} ", pad_left(&i, padding.inode)));
|
||||
write!(result, "{} ", pad_left(&i, padding.inode)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1835,7 +1835,7 @@ fn display_additional_leading_info(
|
|||
} else {
|
||||
"?".to_owned()
|
||||
};
|
||||
result.push_str(&format!("{} ", pad_left(&s, padding.block_size),));
|
||||
write!(result, "{} ", pad_left(&s, padding.block_size)).unwrap();
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
|
|
|
@ -244,7 +244,7 @@ fn format_string(
|
|||
p => format!(
|
||||
"{:<padding$}",
|
||||
number_with_suffix,
|
||||
padding = p.abs() as usize
|
||||
padding = p.unsigned_abs()
|
||||
),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ mod prn_float;
|
|||
mod prn_int;
|
||||
|
||||
use std::cmp;
|
||||
use std::fmt::Write;
|
||||
|
||||
use crate::byteorder_io::*;
|
||||
use crate::formatteriteminfo::*;
|
||||
|
@ -599,11 +600,13 @@ fn print_bytes(prefix: &str, input_decoder: &MemoryDecoder, output_info: &Output
|
|||
|
||||
let mut b = 0;
|
||||
while b < input_decoder.length() {
|
||||
output_text.push_str(&format!(
|
||||
write!(
|
||||
output_text,
|
||||
"{:>width$}",
|
||||
"",
|
||||
width = f.spacing[b % output_info.byte_size_block]
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
match f.formatter_item_info.formatter {
|
||||
FormatWriter::IntWriter(func) => {
|
||||
|
@ -626,12 +629,14 @@ fn print_bytes(prefix: &str, input_decoder: &MemoryDecoder, output_info: &Output
|
|||
let missing_spacing = output_info
|
||||
.print_width_line
|
||||
.saturating_sub(output_text.chars().count());
|
||||
output_text.push_str(&format!(
|
||||
write!(
|
||||
output_text,
|
||||
"{:>width$} {}",
|
||||
"",
|
||||
format_ascii_dump(input_decoder.get_buffer(0)),
|
||||
width = missing_spacing
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
if first {
|
||||
|
|
|
@ -244,7 +244,7 @@ fn is_format_size_decimal(
|
|||
return false;
|
||||
}
|
||||
match ch {
|
||||
Some(d) if d.is_digit(10) => {
|
||||
Some(d) if d.is_ascii_digit() => {
|
||||
decimal_size.push(d);
|
||||
true
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub trait CommandLineOpts {
|
|||
}
|
||||
|
||||
/// Implementation for `getopts`
|
||||
impl<'a> CommandLineOpts for ArgMatches {
|
||||
impl CommandLineOpts for ArgMatches {
|
||||
fn inputs(&self) -> Vec<&str> {
|
||||
self.values_of(options::FILENAME)
|
||||
.map(|values| values.collect())
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::cmp;
|
|||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
use std::default::Default;
|
||||
use std::error::Error;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::fmt::{Display, Formatter, Write as FmtWrite};
|
||||
use std::fs::File;
|
||||
use std::io::{stdin, stdout, BufRead, BufReader, BufWriter, Read, Write};
|
||||
use std::num::ParseIntError;
|
||||
|
@ -572,7 +572,7 @@ fn format_tex_line(
|
|||
reference: &str,
|
||||
) -> String {
|
||||
let mut output = String::new();
|
||||
output.push_str(&format!("\\{} ", config.macro_name));
|
||||
write!(output, "\\{} ", config.macro_name).unwrap();
|
||||
let all_before = if config.input_ref {
|
||||
let before = &line[0..word_ref.position];
|
||||
let before_start_trim_offset =
|
||||
|
@ -587,18 +587,18 @@ fn format_tex_line(
|
|||
let after_chars_trim_idx = (word_ref.position_end, chars_line.len());
|
||||
let all_after = &chars_line[after_chars_trim_idx.0..after_chars_trim_idx.1];
|
||||
let (tail, before, after, head) = get_output_chunks(all_before, keyword, all_after, config);
|
||||
output.push_str(&format!(
|
||||
"{5}{0}{6}{5}{1}{6}{5}{2}{6}{5}{3}{6}{5}{4}{6}",
|
||||
write!(
|
||||
output,
|
||||
"{{{0}}}{{{1}}}{{{2}}}{{{3}}}{{{4}}}",
|
||||
format_tex_field(&tail),
|
||||
format_tex_field(&before),
|
||||
format_tex_field(keyword),
|
||||
format_tex_field(&after),
|
||||
format_tex_field(&head),
|
||||
"{",
|
||||
"}"
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
if config.auto_ref || config.input_ref {
|
||||
output.push_str(&format!("{}{}{}", "{", format_tex_field(reference), "}"));
|
||||
write!(output, "{{{}}}", format_tex_field(reference)).unwrap();
|
||||
}
|
||||
output
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ fn format_roff_line(
|
|||
reference: &str,
|
||||
) -> String {
|
||||
let mut output = String::new();
|
||||
output.push_str(&format!(".{}", config.macro_name));
|
||||
write!(output, ".{}", config.macro_name).unwrap();
|
||||
let all_before = if config.input_ref {
|
||||
let before = &line[0..word_ref.position];
|
||||
let before_start_trim_offset =
|
||||
|
@ -630,16 +630,18 @@ fn format_roff_line(
|
|||
let after_chars_trim_idx = (word_ref.position_end, chars_line.len());
|
||||
let all_after = &chars_line[after_chars_trim_idx.0..after_chars_trim_idx.1];
|
||||
let (tail, before, after, head) = get_output_chunks(all_before, keyword, all_after, config);
|
||||
output.push_str(&format!(
|
||||
write!(
|
||||
output,
|
||||
" \"{}\" \"{}\" \"{}{}\" \"{}\"",
|
||||
format_roff_field(&tail),
|
||||
format_roff_field(&before),
|
||||
format_roff_field(keyword),
|
||||
format_roff_field(&after),
|
||||
format_roff_field(&head)
|
||||
));
|
||||
)
|
||||
.unwrap();
|
||||
if config.auto_ref || config.input_ref {
|
||||
output.push_str(&format!(" \"{}\"", format_roff_field(reference)));
|
||||
write!(output, " \"{}\"", format_roff_field(reference)).unwrap();
|
||||
}
|
||||
output
|
||||
}
|
||||
|
|
|
@ -348,9 +348,9 @@ impl GlobalSettings {
|
|||
];
|
||||
let mut size_string = input.trim().to_string();
|
||||
|
||||
if size_string.ends_with(|c: char| ALLOW_LIST.contains(&c) || c.is_digit(10)) {
|
||||
if size_string.ends_with(|c: char| ALLOW_LIST.contains(&c) || c.is_ascii_digit()) {
|
||||
// b 1, K 1024 (default)
|
||||
if size_string.ends_with(|c: char| c.is_digit(10)) {
|
||||
if size_string.ends_with(|c: char| c.is_ascii_digit()) {
|
||||
size_string.push('K');
|
||||
} else if size_string.ends_with('b') {
|
||||
size_string.pop();
|
||||
|
|
|
@ -197,8 +197,8 @@ impl ScanUtil for str {
|
|||
|
||||
pub fn group_num(s: &str) -> Cow<str> {
|
||||
let is_negative = s.starts_with('-');
|
||||
assert!(is_negative || s.chars().take(1).all(|c| c.is_digit(10)));
|
||||
assert!(s.chars().skip(1).all(|c| c.is_digit(10)));
|
||||
assert!(is_negative || s.chars().take(1).all(|c| c.is_ascii_digit()));
|
||||
assert!(s.chars().skip(1).all(|c| c.is_ascii_digit()));
|
||||
if s.len() < 4 {
|
||||
return s.into();
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ struct ProgramOptions {
|
|||
stderr: BufferType,
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&ArgMatches> for ProgramOptions {
|
||||
impl TryFrom<&ArgMatches> for ProgramOptions {
|
||||
type Error = ProgramOptionsError;
|
||||
|
||||
fn try_from(matches: &ArgMatches) -> Result<Self, Self::Error> {
|
||||
|
|
|
@ -19,7 +19,7 @@ pub fn parse_obsolete(src: &str) -> Option<Result<impl Iterator<Item = OsString>
|
|||
let mut has_num = false;
|
||||
let mut last_char = 0 as char;
|
||||
for (n, c) in &mut chars {
|
||||
if c.is_digit(10) {
|
||||
if c.is_ascii_digit() {
|
||||
has_num = true;
|
||||
num_end = n;
|
||||
} else {
|
||||
|
|
|
@ -50,11 +50,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let mut line = String::new();
|
||||
match reader.read_line(&mut line) {
|
||||
Ok(_) => {
|
||||
let tokens: Vec<String> = line
|
||||
.trim_end()
|
||||
.split_whitespace()
|
||||
.map(|s| s.to_owned())
|
||||
.collect();
|
||||
let tokens: Vec<String> = line.split_whitespace().map(|s| s.to_owned()).collect();
|
||||
if tokens.is_empty() {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use uucore::utmpx::{self, time, Utmpx};
|
|||
use clap::{crate_version, Arg, Command};
|
||||
use std::borrow::Cow;
|
||||
use std::ffi::CStr;
|
||||
use std::fmt::Write;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::path::PathBuf;
|
||||
use uucore::{format_usage, InvalidEncodingHandling};
|
||||
|
@ -528,24 +529,24 @@ impl Who {
|
|||
let mut buf = String::with_capacity(64);
|
||||
let msg = vec![' ', state].into_iter().collect::<String>();
|
||||
|
||||
buf.push_str(&format!("{:<8}", user));
|
||||
write!(buf, "{:<8}", user).unwrap();
|
||||
if self.include_mesg {
|
||||
buf.push_str(&msg);
|
||||
}
|
||||
buf.push_str(&format!(" {:<12}", line));
|
||||
write!(buf, " {:<12}", line).unwrap();
|
||||
// "%b %e %H:%M" (LC_ALL=C)
|
||||
let time_size = 3 + 2 + 2 + 1 + 2;
|
||||
buf.push_str(&format!(" {:<1$}", time, time_size));
|
||||
write!(buf, " {:<1$}", time, time_size).unwrap();
|
||||
|
||||
if !self.short_output {
|
||||
if self.include_idle {
|
||||
buf.push_str(&format!(" {:<6}", idle));
|
||||
write!(buf, " {:<6}", idle).unwrap();
|
||||
}
|
||||
buf.push_str(&format!(" {:>10}", pid));
|
||||
write!(buf, " {:>10}", pid).unwrap();
|
||||
}
|
||||
buf.push_str(&format!(" {:<8}", comment));
|
||||
write!(buf, " {:<8}", comment).unwrap();
|
||||
if self.include_exit {
|
||||
buf.push_str(&format!(" {:<12}", exit));
|
||||
write!(buf, " {:<12}", exit).unwrap();
|
||||
}
|
||||
println!("{}", buf.trim_end());
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ pub fn parse_size(size: &str) -> Result<u64, ParseSizeError> {
|
|||
}
|
||||
// Get the numeric part of the size argument. For example, if the
|
||||
// argument is "123K", then the numeric part is "123".
|
||||
let numeric_string: String = size.chars().take_while(|c| c.is_digit(10)).collect();
|
||||
let numeric_string: String = size.chars().take_while(|c| c.is_ascii_digit()).collect();
|
||||
let number: u64 = if !numeric_string.is_empty() {
|
||||
match numeric_string.parse() {
|
||||
Ok(n) => n,
|
||||
|
|
|
@ -2840,7 +2840,7 @@ fn test_ls_context2() {
|
|||
let ts = TestScenario::new(util_name!());
|
||||
for c_flag in ["-Z", "--context"] {
|
||||
ts.ucmd()
|
||||
.args(&[c_flag, &"/"])
|
||||
.args(&[c_flag, "/"])
|
||||
.succeeds()
|
||||
.stdout_only(unwrap_or_return!(expected_result(&ts, &[c_flag, "/"])).stdout_str());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue