about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorRen Kararou <[email protected]>2023-11-29 10:14:21 -0600
committerRen Kararou <[email protected]>2023-11-29 10:14:21 -0600
commit80b2dd31531f24b070a83f2d56670249b58c6f4b (patch)
tree66696c571db38e676ae821727ca0d9f2f625bf4f
parent6f88870051ed96f809ac20848293571d66da5f1c (diff)
downloadk2spice-80b2dd31531f24b070a83f2d56670249b58c6f4b.tar.gz
k2spice-80b2dd31531f24b070a83f2d56670249b58c6f4b.tar.bz2
k2spice-80b2dd31531f24b070a83f2d56670249b58c6f4b.zip
pass clippy
-rw-r--r--usr/src/mei/printf/src/printf.rs54
1 files changed, 12 insertions, 42 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>) -> 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<char> = 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::<i64>() {
- *                                 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>) -> String {
+    if let Some(i) = d {
+        i.to_string()
+    } else {
+        String::new()
+    }
+}
 
-fn fmtint(s: &str, d: Option<String>) -> String {
+fn fmtuint(_s: &str, d: Option<String>) -> String {
     if let Some(i) = d {
-        format!("{i}")
+        i.to_string()
     } else {
         String::new()
     }
 }
 
-fn chkfmt(chkstr: &str) -> bool {
+fn chkfmt(_chkstr: &str) -> bool {
     // TODO: check if the thing is correct
     true
 }
@@ -130,7 +99,7 @@ fn fmt(fmtstr: String, args: Vec<String>) -> 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>) -> 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
                     _ => (),
                 };