1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

sort: needs support for human-readable block size suffixes R and Q

This commit is contained in:
David Rebbe 2025-01-22 23:35:57 -05:00
parent 93e3d08d5f
commit fb5172eb2a
3 changed files with 11 additions and 5 deletions

View file

@ -48,7 +48,7 @@ rand = "0.8.3"
```rust ```rust
use rand::prelude::*; use rand::prelude::*;
fn main() { fn main() {
let suffixes = ['k', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; let suffixes = ['k', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'R', 'Q'];
let mut rng = thread_rng(); let mut rng = thread_rng();
for _ in 0..100000 { for _ in 0..100000 {
println!( println!(

View file

@ -82,7 +82,10 @@ impl NumInfo {
if Self::is_invalid_char(char, &mut had_decimal_pt, parse_settings) { if Self::is_invalid_char(char, &mut had_decimal_pt, parse_settings) {
return if let Some(start) = start { return if let Some(start) = start {
let has_si_unit = parse_settings.accept_si_units let has_si_unit = parse_settings.accept_si_units
&& matches!(char, 'K' | 'k' | 'M' | 'G' | 'T' | 'P' | 'E' | 'Z' | 'Y'); && matches!(
char,
'K' | 'k' | 'M' | 'G' | 'T' | 'P' | 'E' | 'Z' | 'Y' | 'R' | 'Q'
);
( (
Self { exponent, sign }, Self { exponent, sign },
start..if has_si_unit { idx + 1 } else { idx }, start..if has_si_unit { idx + 1 } else { idx },
@ -176,6 +179,8 @@ fn get_unit(unit: Option<char>) -> u8 {
'E' => 6, 'E' => 6,
'Z' => 7, 'Z' => 7,
'Y' => 8, 'Y' => 8,
'R' => 9,
'Q' => 10,
_ => 0, _ => 0,
} }
} else { } else {

View file

@ -289,7 +289,7 @@ impl GlobalSettings {
// GNU sort (8.32) invalid: b, B, 1B, p, e, z, y // GNU sort (8.32) invalid: b, B, 1B, p, e, z, y
let size = Parser::default() let size = Parser::default()
.with_allow_list(&[ .with_allow_list(&[
"b", "k", "K", "m", "M", "g", "G", "t", "T", "P", "E", "Z", "Y", "b", "k", "K", "m", "M", "g", "G", "t", "T", "P", "E", "Z", "Y", "R", "Q",
]) ])
.with_default_unit("K") .with_default_unit("K")
.with_b_byte_count(true) .with_b_byte_count(true)
@ -535,8 +535,9 @@ impl<'a> Line<'a> {
} else { } else {
// include a trailing si unit // include a trailing si unit
if selector.settings.mode == SortMode::HumanNumeric if selector.settings.mode == SortMode::HumanNumeric
&& self.line[selection.end..initial_selection.end] && self.line[selection.end..initial_selection.end].starts_with(
.starts_with(&['k', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'][..]) &['k', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 'R', 'Q'][..],
)
{ {
selection.end += 1; selection.end += 1;
} }