printf: accept multiple length parameters

This commit is contained in:
Terts Diepraam 2023-11-17 14:41:42 +01:00
parent cd0c24af07
commit f83e0d1b04

View file

@ -107,34 +107,45 @@ impl Spec {
None None
}; };
let length = rest.get(0).and_then(|c| { // Parse 0..N length options, keep the last one
Some(match c { // Even though it is just ignored. We might want to use it later and we
b'h' => { // should parse those characters.
if let Some(b'h') = rest.get(1) { //
*rest = &rest[1..]; // TODO: This needs to be configurable: `seq` accepts only one length
Length::Char // param
} else { let mut _length = None;
Length::Short loop {
let new_length = rest.get(0).and_then(|c| {
Some(match c {
b'h' => {
if let Some(b'h') = rest.get(1) {
*rest = &rest[1..];
Length::Char
} else {
Length::Short
}
} }
} b'l' => {
b'l' => { if let Some(b'l') = rest.get(1) {
if let Some(b'l') = rest.get(1) { *rest = &rest[1..];
*rest = &rest[1..]; Length::Long
Length::Long } else {
} else { Length::LongLong
Length::LongLong }
} }
} b'j' => Length::IntMaxT,
b'j' => Length::IntMaxT, b'z' => Length::SizeT,
b'z' => Length::SizeT, b't' => Length::PtfDiffT,
b't' => Length::PtfDiffT, b'L' => Length::LongDouble,
b'L' => Length::LongDouble, _ => return None,
_ => return None, })
}) });
}); if new_length.is_some() {
*rest = &rest[1..];
if length.is_some() { _length = new_length;
*rest = &rest[1..]; } else {
break;
}
} }
let type_spec = rest.get(0)?; let type_spec = rest.get(0)?;