mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
printf: simplify loop
This commit is contained in:
parent
4e5a65ee41
commit
cd4568f5d9
1 changed files with 6 additions and 3 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue