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 (String => str)

This commit is contained in:
Roy Ivy III 2019-12-27 14:32:44 -06:00
parent 2d95cfdcbd
commit 4ddc65f255
8 changed files with 25 additions and 25 deletions

View file

@ -272,7 +272,7 @@ fn is_format_dump_char(ch: Option<char>, show_ascii_dump: &mut bool) -> bool {
} }
} }
fn parse_type_string(params: &String) -> Result<Vec<ParsedFormatterItemInfo>, String> { fn parse_type_string(params: &str) -> Result<Vec<ParsedFormatterItemInfo>, String> {
let mut formats = Vec::new(); let mut formats = Vec::new();
let mut chars = params.chars(); let mut chars = params.chars();

View file

@ -131,7 +131,7 @@ pub fn parse_inputs_traditional(input_strings: Vec<String>) -> Result<CommandLin
} }
/// parses format used by offset and label on the commandline /// parses format used by offset and label on the commandline
pub fn parse_offset_operand(s: &String) -> Result<usize, &'static str> { pub fn parse_offset_operand(s: &str) -> Result<usize, &'static str> {
let mut start = 0; let mut start = 0;
let mut len = s.len(); let mut len = s.len();
let mut radix = 8; let mut radix = 8;

View file

@ -1,4 +1,4 @@
pub fn parse_number_of_bytes(s: &String) -> Result<usize, &'static str> { pub fn parse_number_of_bytes(s: &str) -> Result<usize, &'static str> {
let mut start = 0; let mut start = 0;
let mut len = s.len(); let mut len = s.len();
let mut radix = 10; let mut radix = 10;

View file

@ -74,9 +74,9 @@ impl Memo {
tkn.print(pf_args_it); tkn.print(pf_args_it);
} }
} }
pub fn run_all(pf_string: &String, pf_args: &[String]) { pub fn run_all(pf_string: &str, pf_args: &[String]) {
let mut arg_it = pf_args.iter().peekable(); let mut arg_it = pf_args.iter().peekable();
let pm = Memo::new(pf_string, &mut arg_it); let pm = Memo::new(&pf_string.to_string(), &mut arg_it);
loop { loop {
if arg_it.peek().is_none() { if arg_it.peek().is_none() {
break; break;

View file

@ -83,7 +83,7 @@ fn get_provided(str_in_opt: Option<&String>) -> Option<u8> {
// a base, // a base,
// and an offset for index after all // and an offset for index after all
// initial spacing, sign, base prefix, and leading zeroes // initial spacing, sign, base prefix, and leading zeroes
fn get_inprefix(str_in: &String, field_type: &FieldType) -> InPrefix { fn get_inprefix(str_in: &str, field_type: &FieldType) -> InPrefix {
let mut str_it = str_in.chars(); let mut str_it = str_in.chars();
let mut ret = InPrefix { let mut ret = InPrefix {
radix_in: Base::Ten, radix_in: Base::Ten,

View file

@ -15,12 +15,12 @@ use super::num_format::format_field::{FieldType, FormatField};
use super::num_format::num_format; use super::num_format::num_format;
// use std::collections::HashSet; // use std::collections::HashSet;
fn err_conv(sofar: &String) { fn err_conv(sofar: &str) {
cli::err_msg(&format!("%{}: invalid conversion specification", sofar)); cli::err_msg(&format!("%{}: invalid conversion specification", sofar));
exit(cli::EXIT_ERR); exit(cli::EXIT_ERR);
} }
fn convert_asterisk_arg_int(asterisk_arg: &String) -> isize { fn convert_asterisk_arg_int(asterisk_arg: &str) -> isize {
// this is a costly way to parse the // this is a costly way to parse the
// args used for asterisk values into integers // args used for asterisk values into integers
// from various bases. Actually doing it correctly // from various bases. Actually doing it correctly
@ -32,11 +32,11 @@ fn convert_asterisk_arg_int(asterisk_arg: &String) -> isize {
let field_info = FormatField { let field_info = FormatField {
min_width: Some(0), min_width: Some(0),
second_field: Some(0), second_field: Some(0),
orig: asterisk_arg, orig: &asterisk_arg.to_string(),
field_type: &field_type, field_type: &field_type,
field_char: &field_char, field_char: &field_char,
}; };
num_format::num_format(&field_info, Some(asterisk_arg)) num_format::num_format(&field_info, Some(&asterisk_arg.to_string()))
.unwrap() .unwrap()
.parse::<isize>() .parse::<isize>()
.unwrap() .unwrap()

View file

@ -49,7 +49,7 @@ struct Settings {
unique: bool, unique: bool,
check: bool, check: bool,
ignore_case: bool, ignore_case: bool,
compare_fns: Vec<fn(&String, &String) -> Ordering>, compare_fns: Vec<fn(&str, &str) -> Ordering>,
} }
impl Default for Settings { impl Default for Settings {
@ -352,13 +352,13 @@ fn sort_by(lines: &mut Vec<String>, settings: &Settings) {
lines.sort_by(|a, b| compare_by(a, b, &settings)) lines.sort_by(|a, b| compare_by(a, b, &settings))
} }
fn compare_by(a: &String, b: &String, settings: &Settings) -> Ordering { fn compare_by(a: &str, b: &str, settings: &Settings) -> Ordering {
// Convert to uppercase if necessary // Convert to uppercase if necessary
let (a_upper, b_upper): (String, String); let (a_upper, b_upper): (String, String);
let (a, b) = if settings.ignore_case { let (a, b) = if settings.ignore_case {
a_upper = a.to_uppercase(); a_upper = a.to_uppercase();
b_upper = b.to_uppercase(); b_upper = b.to_uppercase();
(&a_upper, &b_upper) (&*a_upper, &*b_upper)
} else { } else {
(a, b) (a, b)
}; };
@ -402,7 +402,7 @@ fn default_compare(a: &str, b: &str) -> Ordering {
/// Compares two floating point numbers, with errors being assumed to be -inf. /// Compares two floating point numbers, with errors being assumed to be -inf.
/// Stops coercing at the first whitespace char, so 1e2 will parse as 100 but /// Stops coercing at the first whitespace char, so 1e2 will parse as 100 but
/// 1,000 will parse as -inf. /// 1,000 will parse as -inf.
fn numeric_compare(a: &String, b: &String) -> Ordering { fn numeric_compare(a: &str, b: &str) -> Ordering {
let fa = permissive_f64_parse(a); let fa = permissive_f64_parse(a);
let fb = permissive_f64_parse(b); let fb = permissive_f64_parse(b);
// f64::cmp isn't implemented because NaN messes with it // f64::cmp isn't implemented because NaN messes with it
@ -416,7 +416,7 @@ fn numeric_compare(a: &String, b: &String) -> Ordering {
} }
} }
fn human_numeric_convert(a: &String) -> f64 { fn human_numeric_convert(a: &str) -> f64 {
let int_iter = a.chars(); let int_iter = a.chars();
let suffix_iter = a.chars(); let suffix_iter = a.chars();
let int_str: String = int_iter.take_while(|c| c.is_numeric()).collect(); let int_str: String = int_iter.take_while(|c| c.is_numeric()).collect();
@ -438,7 +438,7 @@ fn human_numeric_convert(a: &String) -> f64 {
/// Compare two strings as if they are human readable sizes. /// Compare two strings as if they are human readable sizes.
/// AKA 1M > 100k /// AKA 1M > 100k
fn human_numeric_size_compare(a: &String, b: &String) -> Ordering { fn human_numeric_size_compare(a: &str, b: &str) -> Ordering {
let fa = human_numeric_convert(a); let fa = human_numeric_convert(a);
let fb = human_numeric_convert(b); let fb = human_numeric_convert(b);
if fa > fb { if fa > fb {
@ -468,7 +468,7 @@ enum Month {
} }
/// Parse the beginning string into a Month, returning Month::Unknown on errors. /// Parse the beginning string into a Month, returning Month::Unknown on errors.
fn month_parse(line: &String) -> Month { fn month_parse(line: &str) -> Month {
match line.split_whitespace() match line.split_whitespace()
.next() .next()
.unwrap() .unwrap()
@ -491,11 +491,11 @@ fn month_parse(line: &String) -> Month {
} }
} }
fn month_compare(a: &String, b: &String) -> Ordering { fn month_compare(a: &str, b: &str) -> Ordering {
month_parse(a).cmp(&month_parse(b)) month_parse(a).cmp(&month_parse(b))
} }
fn version_compare(a: &String, b: &String) -> Ordering { fn version_compare(a: &str, b: &str) -> Ordering {
let ver_a = Version::parse(a); let ver_a = Version::parse(a);
let ver_b = Version::parse(b); let ver_b = Version::parse(b);
if ver_a > ver_b { if ver_a > ver_b {

View file

@ -135,12 +135,12 @@ impl Graph {
self.in_edges.get(to).unwrap().contains(from) self.in_edges.get(to).unwrap().contains(from)
} }
fn init_node(&mut self, n: &String) { fn init_node(&mut self, n: &str) {
self.in_edges.insert(n.clone(), HashSet::new()); self.in_edges.insert(n.to_string(), HashSet::new());
self.out_edges.insert(n.clone(), vec![]); self.out_edges.insert(n.to_string(), vec![]);
} }
fn add_edge(&mut self, from: &String, to: &String) { fn add_edge(&mut self, from: &str, to: &str) {
if !self.has_node(to) { if !self.has_node(to) {
self.init_node(to); self.init_node(to);
} }
@ -150,8 +150,8 @@ impl Graph {
} }
if from != to && !self.has_edge(from, to) { if from != to && !self.has_edge(from, to) {
self.in_edges.get_mut(to).unwrap().insert(from.clone()); self.in_edges.get_mut(to).unwrap().insert(from.to_string());
self.out_edges.get_mut(from).unwrap().push(to.clone()); self.out_edges.get_mut(from).unwrap().push(to.to_string());
} }
} }