Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
9 changes: 7 additions & 2 deletions src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,14 +671,19 @@ impl<'a> Line<'a> {
_ => {}
}

// Don't let embedded NUL bytes influence column alignment in the
// debug underline output, since they are often filtered out (e.g.
// via `tr -d '\0'`) before inspection.
let select = &line[..selection.start];
write!(writer, "{}", " ".repeat(select.len()))?;
let indent = select.iter().filter(|&&c| c != b'\0').count();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please create a function for the filter
something like

fn count_non_null_bytes(bytes: &[u8]) -> usize {
    bytes.iter().filter(|&&c| c != b'\0').count()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

write!(writer, "{}", " ".repeat(indent))?;

if selection.is_empty() {
writeln!(writer, "{}", translate!("sort-error-no-match-for-key"))?;
} else {
let select = &line[selection];
writeln!(writer, "{}", "_".repeat(select.len()))?;
let underline_len = select.iter().filter(|&&c| c != b'\0').count();
writeln!(writer, "{}", "_".repeat(underline_len))?;
}
}

Expand Down
Loading
Loading