Skip to content
Myr

Update regex and match, update comments

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Steve Pentland · committed by David Peter · parent ace3f51 · Browse files · 1 file+16 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+16 added−12 removed

  • other:+16 added−12 removed

1 file+16 added−12 removed

modified:src/internal.rs+16 added-12 removed
17 unmodified lines
18use regex_syntax::hir::Hir;19use regex_syntax::Parser;2021lazy_static! {22 static ref SIZE_CAPTURES: Regex = { Regex::new(r"(?i)^([+-])(\d+)([bkmgt]i?)b?$").unwrap() };22 static ref SIZE_CAPTURES: Regex = { Regex::new(r"(?i)^([+-])(\d+)(b|[kmgt]i?b?)$").unwrap() };23}2425/// Whether or not to show26pub struct FileTypes {
25 unmodified lines
52 size: u64,53 limit_type: SizeLimitType,54}5556// SI units for now56// SI prefixes (powers of 10)57const KILO: u64 = 1000;58const MEGA: u64 = KILO * 1000;59const GIGA: u64 = MEGA * 1000;60const TERA: u64 = GIGA * 1000;6162// Binary prefixes (powers of 2)63const KIBI: u64 = 1024;64const MEBI: u64 = KIBI * 1024;65const GIBI: u64 = MEBI * 1024;66const TEBI: u64 = GIBI * 1024;
21 unmodified lines
88 _ => return None,89 },90 };9191 let multiplier = match &captures.get(3).map_or("k", |m| m.as_str()).to_lowercase()[..] {92 "ki" => KIBI,93 "k" => KILO,94 "mi" => MEBI,95 "m" => MEGA,96 "gi" => GIBI,97 "g" => GIGA,98 "ti" => TEBI,99 "t" => TERA,100 _ => 1, // Any we don't understand we'll just say the number of bytes92 let multiplier = match &captures.get(3).map_or("b", |m| m.as_str()).to_lowercase()[..] {93 v if v.starts_with("ki") => KIBI,94 v if v.starts_with("k") => KILO,95 v if v.starts_with("mi") => MEBI,96 v if v.starts_with("m") => MEGA,97 v if v.starts_with("gi") => GIBI,98 v if v.starts_with("g") => GIGA,99 v if v.starts_with("ti") => TEBI,100 v if v.starts_with("t") => TERA,101 "b" => 1,102 _ => return None,103 };104105 Some(SizeFilter {106 size: quantity * multiplier,
346 unmodified lines
453 ensure_bad_format_returns_none_3: "9999",454 ensure_invalid_unit_returns_none_1: "+50a",455 ensure_invalid_unit_returns_none_2: "-10v",456 ensure_invalid_unit_returns_none_3: "+1Mv",457 ensure_bib_format_returns_none: "+1bib",458 ensure_bb_format_returns_none: "+1bb",459}460461#[test]462fn is_within_less_than() {
21 unmodified lines