mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #7198 from ic3man5/issue_7182
sort: needs support for human-readable block size suffixes R and Q
This commit is contained in:
commit
5b056704da
4 changed files with 22 additions and 5 deletions
|
@ -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!(
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1313,3 +1313,14 @@ fn test_k_overflow() {
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_is(output);
|
.stdout_is(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_human_blocks_r_and_q() {
|
||||||
|
let input = "1Q\n1R\n";
|
||||||
|
let output = "1R\n1Q\n";
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["-h"])
|
||||||
|
.pipe_in(input)
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is(output);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue