Browse Source

enhance: allow underscore in number literal arguments

pull/28/head
Andelf 1 year ago
parent
commit
19b5365315
  1. 4
      CHANGELOG.md
  2. 5
      src/main.rs

4
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

5
src/main.rs

@ -245,10 +245,11 @@ fn main() -> Result<()> {
}
pub fn parse_number(s: &str) -> std::result::Result<u32, String> {
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 {

Loading…
Cancel
Save