pub fn parse(s: &str) -> Result<usize, ParseIntError>Expand description
Parse a numeric string with an optional one-or-two character multiplicative
suffix (K, KB, M, MB, …)
into an integer. Numeric strings may be decimal, octal, or hexadecimal.
Multiple numeric strings may be multipled together by separating them with
the ‘X’ character. See number/units for a list of the SI suffixes.
#use dd::opts::number::parse;
vec![
("base case", "2", Some(2)),
("two ok", "0x18X21", Some(0x18 * 21)),
("mixed types", "0x11X0o22X2", Some(0x11 * 0o22 * 2)),
("multiple suffixes", "0x13MX9K", Some(0x13 * M * 9 * K)),
("bad string", "asjopdajsdomasd", None),
]
.into_iter()
.for_each(|(name, s, want)| {
let got = parse(s).ok();
assert_eq!(
want, got,
r#"{}: want number("{}") = {:?}, but got {:?}"#,
name, s, want, got
);
})