From 80b2dd31531f24b070a83f2d56670249b58c6f4b Mon Sep 17 00:00:00 2001 From: Ren Kararou Date: Wed, 29 Nov 2023 10:14:21 -0600 Subject: [PATCH] pass clippy --- usr/src/mei/printf/src/printf.rs | 56 ++++++++------------------------ 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/usr/src/mei/printf/src/printf.rs b/usr/src/mei/printf/src/printf.rs index b343e6d..4d30c64 100644 --- a/usr/src/mei/printf/src/printf.rs +++ b/usr/src/mei/printf/src/printf.rs @@ -71,54 +71,23 @@ fn escape(escstr: String) -> String { im.clone() } -/* - * fn fmt(fmtstr: String, args: Vec) -> String { - * let mut formatted: String = "".to_string(); - * let mut data = args.into_iter(); - * let fmtiter = fmtstr.clone(); - * let mut fmtiter = fmtiter.chars().peekable(); - * for _idx in 1..fmtstr.len() { - * let c: Option = fmtiter.next(); - * match c { - * Some('%') => { - * let next: char = if let Some(v) = fmtiter.next() { - * v - * } else { - * formatted += String::from('%').as_str(); - * break; - * }; - * match next { - * 'd' => { - * if let Some(arg) = data.next() { - * if let Ok(i) = arg.parse::() { - * formatted += String::from(format!("{i}")).as_str(); - * } else { - * eprintln!("printf: trying to format non-int data as int"); - * } - * } else { - * eprintln!("printf: format argument not supplied"); - * } - * }, - * _ => formatted += {String::from('%') + String::from(next).as_str()}.as_str(), - * } - * }, - * Some(c) => formatted += String::from(c).as_str(), - * None => break, - * } - * } - * formatted.clone() - * } - */ - -fn fmtint(s: &str, d: Option) -> String { +fn fmtint(_s: &str, d: Option) -> String { if let Some(i) = d { - format!("{i}") + i.to_string() } else { String::new() } } -fn chkfmt(chkstr: &str) -> bool { +fn fmtuint(_s: &str, d: Option) -> String { + if let Some(i) = d { + i.to_string() + } else { + String::new() + } +} + +fn chkfmt(_chkstr: &str) -> bool { // TODO: check if the thing is correct true } @@ -130,7 +99,7 @@ fn fmt(fmtstr: String, args: Vec) -> String { let mut i = 0; while i < fmtb.len() { if fmtb[i] == b'%' { - if !(i + 1 >= fmtb.len()) { + if i + 1 < fmtb.len() { let mut xe = i + 1; // find end of format specifier and get its index while xe < fmtb.len() { @@ -147,6 +116,7 @@ fn fmt(fmtstr: String, args: Vec) -> String { } match fmtb[xe] { b'd' => formatted += fmtint(&fmtstr[i..xe], args.next()).as_str(), + b'u' => formatted += fmtuint(&fmtstr[i..xe], args.next()).as_str(), // at this point, this match should be impossible _ => (), };