From 6a848b14f8937a2d552f03c5ce363229fcfdae10 Mon Sep 17 00:00:00 2001 From: Mikaela Szekely Date: Sat, 19 Jan 2019 18:21:19 -0700 Subject: [PATCH] Allow passing length in hex with 0x notation --- Cargo.lock | 2 ++ src/main.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e2bb7fe..45123a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "ansi_term" version = "0.11.0" diff --git a/src/main.rs b/src/main.rs index 07b65a2..4a12d86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -274,7 +274,15 @@ fn run() -> Result<(), Box<::std::error::Error>> { let length_arg = matches.value_of("length").or(matches.value_of("bytes")); - if let Some(length) = length_arg.and_then(|n| n.parse::().ok()) { + if let Some(length) = length_arg.and_then(|n| { + if n.starts_with("0x") { + u64::from_str_radix(n.trim_start_matches("0x"), 16).ok() + } + else { + n.parse::().ok() + } + }) + { reader = Box::new(reader.take(length)); }