From 95388147020b2687e04959327a6962fe37654844 Mon Sep 17 00:00:00 2001 From: Terts Diepraam Date: Tue, 8 Feb 2022 14:20:24 +0100 Subject: [PATCH] shuf: use split_once for parsing the range --- src/uu/shuf/src/shuf.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 058ac8637..3dcd7b0e2 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -288,17 +288,16 @@ fn shuf_bytes(input: &mut Vec<&[u8]>, opts: Options) -> UResult<()> { } fn parse_range(input_range: &str) -> Result<(usize, usize), String> { - let split: Vec<&str> = input_range.split('-').collect(); - if split.len() != 2 { - Err(format!("invalid input range: {}", input_range.quote())) - } else { - let begin = split[0] + if let Some((from, to)) = input_range.split_once('-') { + let begin = from .parse::() - .map_err(|_| format!("invalid input range: {}", split[0].quote()))?; - let end = split[1] + .map_err(|_| format!("invalid input range: {}", from.quote()))?; + let end = to .parse::() - .map_err(|_| format!("invalid input range: {}", split[1].quote()))?; + .map_err(|_| format!("invalid input range: {}", to.quote()))?; Ok((begin, end + 1)) + } else { + Err(format!("invalid input range: {}", input_range.quote())) } }