mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +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![],
|
None => vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut format_seen = false;
|
||||||
let mut args = values.iter().peekable();
|
let mut args = values.iter().peekable();
|
||||||
for item in parse_spec_and_escape(format_string.as_ref()) {
|
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)? {
|
match item?.write(stdout(), &mut args)? {
|
||||||
ControlFlow::Continue(()) => {}
|
ControlFlow::Continue(()) => {}
|
||||||
ControlFlow::Break(()) => return Ok(()),
|
ControlFlow::Break(()) => return Ok(()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// See #5815 - We don't need to iter on args if no format string seen
|
// Without format specs in the string, the iter would not consume any args,
|
||||||
let format_seen =
|
// leading to an infinite loop. Thus, we exit early.
|
||||||
parse_spec_and_escape(format_string.as_ref()).any(|r| matches!(r, Ok(FormatItem::Spec(_))));
|
|
||||||
if !format_seen {
|
if !format_seen {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue