mirror of
https://git.sr.ht/~spicywolf/k2spice
synced 2025-01-18 09:49:38 +00:00
pass clippy
This commit is contained in:
parent
6f88870051
commit
80b2dd3153
|
@ -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 {
|
||||
fn fmtint(_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 fmtuint(_s: &str, d: Option<String>) -> 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>) -> 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
|
||||
_ => (),
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue