Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
891ab02
feat(fold): add --characters option to count by character positions
mattsu2020 Nov 3, 2025
95d73d0
refactor(fold): introduce FoldContext to encapsulate state and simpli…
mattsu2020 Nov 3, 2025
26906fe
feat: optimize ASCII line processing in fold
mattsu2020 Nov 3, 2025
5fc3dc2
feat: add rposition to jargon wordlist
mattsu2020 Nov 3, 2025
980c8b1
perf: optimize fold benchmarks and output handling
mattsu2020 Nov 4, 2025
639a451
refactor(fold): improve readability of last_space assignment in emit_…
mattsu2020 Nov 4, 2025
f468a41
fix(fold): correct space index condition in emit_output
mattsu2020 Nov 4, 2025
9ed32fe
refactor(fold): optimize ASCII line processing for better character h…
mattsu2020 Nov 4, 2025
265aeb5
feat(fold): add --characters option to count by character positions
mattsu2020 Nov 3, 2025
28e1a65
refactor(fold): introduce FoldContext to encapsulate state and simpli…
mattsu2020 Nov 3, 2025
65b1fd4
feat: optimize ASCII line processing in fold
mattsu2020 Nov 3, 2025
54c2308
feat: add rposition to jargon wordlist
mattsu2020 Nov 3, 2025
578f6d4
perf: optimize fold benchmarks and output handling
mattsu2020 Nov 4, 2025
3b593d7
refactor(fold): improve readability of last_space assignment in emit_…
mattsu2020 Nov 4, 2025
e06aec9
fix(fold): correct space index condition in emit_output
mattsu2020 Nov 4, 2025
7e17a51
refactor(fold): optimize ASCII line processing for better character h…
mattsu2020 Nov 4, 2025
fbefe63
refactor(fold): unify UTF-8 and non-UTF-8 handling paths
mattsu2020 Nov 12, 2025
ff1a312
Resolve fold conflict
mattsu2020 Nov 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(fold): unify UTF-8 and non-UTF-8 handling paths
- Simplify fold_file by sharing FoldContext construction
- Reduces duplicated code and improves maintainability without behavior change
  • Loading branch information
mattsu2020 committed Nov 12, 2025
commit fbefe63537208f8feb24fca032df4531f99acf0c
35 changes: 13 additions & 22 deletions src/uu/fold/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,28 +577,19 @@ fn fold_file<T: Read, W: Write>(
break;
}

if let Ok(line_str) = std::str::from_utf8(&line) {
let mut ctx = FoldContext {
spaces,
width,
mode,
writer,
output: &mut output,
col_count: &mut col_count,
last_space: &mut last_space,
};
process_utf8_line(line_str, &mut ctx)?;
} else {
let mut ctx = FoldContext {
spaces,
width,
mode,
writer,
output: &mut output,
col_count: &mut col_count,
last_space: &mut last_space,
};
process_non_utf8_line(&line, &mut ctx)?;
let mut ctx = FoldContext {
spaces,
width,
mode,
writer,
output: &mut output,
col_count: &mut col_count,
last_space: &mut last_space,
};

match std::str::from_utf8(&line) {
Ok(s) => process_utf8_line(s, &mut ctx)?,
Err(_) => process_non_utf8_line(&line, &mut ctx)?,
}

line.clear();
Expand Down