mirror of
https://github.com/uutils/coreutils
synced 2024-11-17 02:08:09 +00:00
shuf: use split_once for parsing the range
This commit is contained in:
parent
30ae952b83
commit
9538814702
1 changed files with 7 additions and 8 deletions
|
@ -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::<usize>()
|
||||
.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::<usize>()
|
||||
.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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue