mirror of
https://github.com/uutils/coreutils
synced 2024-10-15 04:14:44 +00:00
printf: simplify loop
This commit is contained in:
parent
4e5a65ee41
commit
cd4568f5d9
|
@ -38,17 +38,20 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
None => vec![],
|
||||
};
|
||||
|
||||
let mut format_seen = false;
|
||||
let mut args = values.iter().peekable();
|
||||
for item in parse_spec_and_escape(format_string.as_ref()) {
|
||||
if let Ok(FormatItem::Spec(_)) = item {
|
||||
format_seen = true;
|
||||
}
|
||||
match item?.write(stdout(), &mut args)? {
|
||||
ControlFlow::Continue(()) => {}
|
||||
ControlFlow::Break(()) => return Ok(()),
|
||||
};
|
||||
}
|
||||
|
||||
// See #5815 - We don't need to iter on args if no format string seen
|
||||
let format_seen =
|
||||
parse_spec_and_escape(format_string.as_ref()).any(|r| matches!(r, Ok(FormatItem::Spec(_))));
|
||||
// Without format specs in the string, the iter would not consume any args,
|
||||
// leading to an infinite loop. Thus, we exit early.
|
||||
if !format_seen {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue