From 1269722770be48f7f78442e39e58db18d4f69d58 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 2 Apr 2024 09:44:35 +1100 Subject: [PATCH] Move helper function Move the `strip_hex_prefix` helper function to below where it is called. Note that I was the original author of this helper so there is no excuse for it being above - bad Tobin no biscuit. --- units/src/parse.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) 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]