From b705e42c5ae0701ba0305ebbf6a7338da41e86cc Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Tue, 11 Aug 2026 22:18:35 +0900 Subject: [PATCH] unexpand: simplify loop by while let --- src/uu/unexpand/src/unexpand.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/uu/unexpand/src/unexpand.rs b/src/uu/unexpand/src/unexpand.rs index dab1c396fe9..d45da4ba46d 100644 --- a/src/uu/unexpand/src/unexpand.rs +++ b/src/uu/unexpand/src/unexpand.rs @@ -651,23 +651,19 @@ fn unexpand_file( pending_wide: Vec::new(), }; - loop { - match input.read(buf) { - Ok(0) => break, - Ok(n) => { - for line in buf[..n].split_inclusive(|b| *b == b'\n') { - unexpand_buf(line, output, options, lastcol, tab_config, &mut print_state)?; - if let Some(b'\n') = line.last() { - print_state.new_line(); - } - } + while let n @ 1.. = input + .read(buf) + .map_err(|e| e.map_err_context(|| file.maybe_quote().to_string()) as Box)? + { + for line in buf[..n].split_inclusive(|b| *b == b'\n') { + unexpand_buf(line, output, options, lastcol, tab_config, &mut print_state)?; + if let Some(b'\n') = line.last() { + print_state.new_line(); } - Err(e) => return Err(e.map_err_context(|| file.maybe_quote().to_string())), } } // write out anything remaining - write_tabs(output, tab_config, &mut print_state, options.aflag)?; - Ok(()) + write_tabs(output, tab_config, &mut print_state, options.aflag) } fn unexpand(options: &Options) -> UResult<()> {