mirror of
https://github.com/sharkdp/fd
synced 2024-11-02 15:11:27 +00:00
Update regex and match, update comments
This commit is contained in:
parent
ace3f512d3
commit
0bbc7f5219
1 changed files with 16 additions and 12 deletions
|
@ -19,7 +19,7 @@ use regex_syntax::hir::Hir;
|
||||||
use regex_syntax::Parser;
|
use regex_syntax::Parser;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref SIZE_CAPTURES: Regex = { Regex::new(r"(?i)^([+-])(\d+)([bkmgt]i?)b?$").unwrap() };
|
static ref SIZE_CAPTURES: Regex = { Regex::new(r"(?i)^([+-])(\d+)(b|[kmgt]i?b?)$").unwrap() };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether or not to show
|
/// Whether or not to show
|
||||||
|
@ -53,12 +53,13 @@ pub struct SizeFilter {
|
||||||
limit_type: SizeLimitType,
|
limit_type: SizeLimitType,
|
||||||
}
|
}
|
||||||
|
|
||||||
// SI units for now
|
// SI prefixes (powers of 10)
|
||||||
const KILO: u64 = 1000;
|
const KILO: u64 = 1000;
|
||||||
const MEGA: u64 = KILO * 1000;
|
const MEGA: u64 = KILO * 1000;
|
||||||
const GIGA: u64 = MEGA * 1000;
|
const GIGA: u64 = MEGA * 1000;
|
||||||
const TERA: u64 = GIGA * 1000;
|
const TERA: u64 = GIGA * 1000;
|
||||||
|
|
||||||
|
// Binary prefixes (powers of 2)
|
||||||
const KIBI: u64 = 1024;
|
const KIBI: u64 = 1024;
|
||||||
const MEBI: u64 = KIBI * 1024;
|
const MEBI: u64 = KIBI * 1024;
|
||||||
const GIBI: u64 = MEBI * 1024;
|
const GIBI: u64 = MEBI * 1024;
|
||||||
|
@ -88,16 +89,17 @@ impl SizeFilter {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let multiplier = match &captures.get(3).map_or("k", |m| m.as_str()).to_lowercase()[..] {
|
let multiplier = match &captures.get(3).map_or("b", |m| m.as_str()).to_lowercase()[..] {
|
||||||
"ki" => KIBI,
|
v if v.starts_with("ki") => KIBI,
|
||||||
"k" => KILO,
|
v if v.starts_with("k") => KILO,
|
||||||
"mi" => MEBI,
|
v if v.starts_with("mi") => MEBI,
|
||||||
"m" => MEGA,
|
v if v.starts_with("m") => MEGA,
|
||||||
"gi" => GIBI,
|
v if v.starts_with("gi") => GIBI,
|
||||||
"g" => GIGA,
|
v if v.starts_with("g") => GIGA,
|
||||||
"ti" => TEBI,
|
v if v.starts_with("ti") => TEBI,
|
||||||
"t" => TERA,
|
v if v.starts_with("t") => TERA,
|
||||||
_ => 1, // Any we don't understand we'll just say the number of bytes
|
"b" => 1,
|
||||||
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(SizeFilter {
|
Some(SizeFilter {
|
||||||
|
@ -452,6 +454,8 @@ gen_size_filter_failure! {
|
||||||
ensure_invalid_unit_returns_none_1: "+50a",
|
ensure_invalid_unit_returns_none_1: "+50a",
|
||||||
ensure_invalid_unit_returns_none_2: "-10v",
|
ensure_invalid_unit_returns_none_2: "-10v",
|
||||||
ensure_invalid_unit_returns_none_3: "+1Mv",
|
ensure_invalid_unit_returns_none_3: "+1Mv",
|
||||||
|
ensure_bib_format_returns_none: "+1bib",
|
||||||
|
ensure_bb_format_returns_none: "+1bb",
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue