Skip to content

Commit

Permalink
Remove the dependency on parse_int in favour of from_str_radix
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Feb 10, 2025
1 parent ad1cb9f commit e8ab791
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions espflash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ indicatif = { version = "0.17.9", optional = true }
log = "0.4.22"
md-5 = "0.10.6"
miette = "7.4.0"
parse_int = { version = "0.6.0", optional = true }
regex = { version = "1.11.1", optional = true }
serde = { version = "1.0.217", features = ["derive"] }
serialport = { version = "4.7.0", default-features = false, optional = true }
Expand Down Expand Up @@ -73,7 +72,6 @@ cli = [
"dep:directories",
"dep:env_logger",
"dep:indicatif",
"dep:parse_int",
"dep:toml",
"dep:update-informer",
"miette/fancy",
Expand Down
10 changes: 8 additions & 2 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,15 @@ pub struct ChecksumMd5Args {
connect_args: ConnectArgs,
}

/// Parses an integer, in base-10 or hexadecimal format, into a [u32].
/// Parses an integer, in base-10 or hexadecimal format, into a [u32]
pub fn parse_u32(input: &str) -> Result<u32, ParseIntError> {
parse_int::parse(input)
let (s, radix) = if matches!(&input[0..2], "0x" | "0X") {
(&input[2..], 16)
} else {
(input, 10)
};

u32::from_str_radix(s, radix)
}

/// Select a serial port and establish a connection with a target device
Expand Down
4 changes: 2 additions & 2 deletions espflash/src/cli/monitor/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub trait InputParser {
}

// Pattern to much a function address in serial output.
static RE_FN_ADDR: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"0x[[:xdigit:]]{8}").unwrap());
static RE_FN_ADDR: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"0[xX][[:xdigit:]]{8}").unwrap());

fn resolve_addresses(
symbols: &Symbols<'_>,
Expand All @@ -30,7 +30,7 @@ fn resolve_addresses(
// Since our regular expression already confirms that this is a correctly
// formatted hex literal, we can (fairly) safely assume that it will parse
// successfully into an integer.
let addr = parse_int::parse::<u64>(matched).unwrap();
let addr = u64::from_str_radix(&matched[2..], 16).unwrap();

let name = symbols.get_name(addr);
let location = symbols.get_location(addr);
Expand Down

0 comments on commit e8ab791

Please sign in to comment.