Skip to content

Commit

Permalink
feat: Allow underscores in parse_u32
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioGasquez committed Feb 12, 2025
1 parent 6fb20aa commit b0f0432
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,8 @@ use crate::{
elf::ElfFirmwareImage,
error::{Error, MissingPartition, MissingPartitionTable},
flasher::{
parse_partition_table,
FlashData,
FlashFrequency,
FlashMode,
FlashSettings,
FlashSize,
Flasher,
ProgressCallbacks,
parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSettings, FlashSize,
Flasher, ProgressCallbacks,
},
targets::{Chip, XtalFrequency},
};
Expand Down Expand Up @@ -300,6 +294,7 @@ pub struct ChecksumMd5Args {

/// Parses an integer, in base-10 or hexadecimal format, into a [u32]
pub fn parse_u32(input: &str) -> Result<u32, ParseIntError> {
let input: &str = &input.replace('_', "");
let (s, radix) = if input.len() > 2 && matches!(&input[0..2], "0x" | "0X") {
(&input[2..], 16)
} else {
Expand Down Expand Up @@ -892,6 +887,9 @@ mod test {
// Decimal
assert_eq!(parse_u32("1234"), Ok(1234));
assert_eq!(parse_u32("0"), Ok(0));
// Underscores
assert_eq!(parse_u32("12_34"), Ok(1234));
assert_eq!(parse_u32("0X12_34"), Ok(0x1234));
// Errors
assert!(parse_u32("").is_err());
assert!(parse_u32("0x").is_err());
Expand Down

0 comments on commit b0f0432

Please sign in to comment.