diff --git a/CHANGELOG.md b/CHANGELOG.md index 9db4285..4dd2cd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Regression in `flash` command +### Changed + +- Allow underscore `_` in number literals in command line + ## [0.0.5] - 2023-07-31 ### Added diff --git a/src/main.rs b/src/main.rs index ba33e6f..723124f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -245,10 +245,11 @@ fn main() -> Result<()> { } pub fn parse_number(s: &str) -> std::result::Result { - if s.starts_with("0x") || s.starts_with("0X") { + let s = s.replace("_", "").to_lowercase(); + if s.starts_with("0x") { Ok(u32::from_str_radix(&s[2..], 16) .unwrap_or_else(|_| panic!("error while parsering {s:?}"))) - } else if s.starts_with("0b") || s.starts_with("0B") { + } else if s.starts_with("0b") { Ok(u32::from_str_radix(&s[2..], 2) .unwrap_or_else(|_| panic!("error while parsering {s:?}"))) } else {