diff --git a/units/src/parse.rs b/units/src/parse.rs index 83ea5980..9ace652f 100644 --- a/units/src/parse.rs +++ b/units/src/parse.rs @@ -88,17 +88,6 @@ pub fn int + Into>(s: S) -> Result &str { - if let Some(stripped) = s.strip_prefix("0x") { - stripped - } else if let Some(stripped) = s.strip_prefix("0X") { - stripped - } else { - s - } -} - /// Parses a u32 from a hex string. /// /// Input string may or may not contain a `0x` prefix. @@ -111,6 +100,17 @@ pub fn hex_u32 + Into>(s: S) -> Result }) } +/// Strips the hex prefix off `s` if one is present. +pub(crate) fn strip_hex_prefix(s: &str) -> &str { + if let Some(stripped) = s.strip_prefix("0x") { + stripped + } else if let Some(stripped) = s.strip_prefix("0X") { + stripped + } else { + s + } +} + /// Implements `TryFrom<$from> for $to` using `parse::int`, mapping the output using infallible /// conversion function `fn`. #[macro_export]