Skip to content

Commit b0f0432

Browse files
committed
feat: Allow underscores in parse_u32
1 parent 6fb20aa commit b0f0432

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

espflash/src/cli/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,8 @@ use crate::{
3737
elf::ElfFirmwareImage,
3838
error::{Error, MissingPartition, MissingPartitionTable},
3939
flasher::{
40-
parse_partition_table,
41-
FlashData,
42-
FlashFrequency,
43-
FlashMode,
44-
FlashSettings,
45-
FlashSize,
46-
Flasher,
47-
ProgressCallbacks,
40+
parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSettings, FlashSize,
41+
Flasher, ProgressCallbacks,
4842
},
4943
targets::{Chip, XtalFrequency},
5044
};
@@ -300,6 +294,7 @@ pub struct ChecksumMd5Args {
300294

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

0 commit comments

Comments
 (0)