diff --git a/src/patch/mod.rs b/src/patch/mod.rs index 738521b9..572513d5 100644 --- a/src/patch/mod.rs +++ b/src/patch/mod.rs @@ -1,6 +1,7 @@ pub mod patch_cli; use globset::Glob; +use regex::Regex; use std::fs::File; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; @@ -571,19 +572,13 @@ fn make_cpu(cmod: &Hash) -> Result { /// Find left and right indices of enumeration token in specification string fn spec_ind(spec: &str) -> (usize, usize) { let spec = spec.split(',').next().unwrap_or(spec); - let li = spec - .bytes() - .position(|b| b == b'*') - .or_else(|| spec.bytes().position(|b| b == b'?')) - .or_else(|| spec.bytes().position(|b| b == b'[')) - .unwrap(); - let ri = spec - .bytes() - .rev() - .position(|b| b == b'*') - .or_else(|| spec.bytes().rev().position(|b| b == b'?')) - .or_else(|| spec.bytes().rev().position(|b| b == b']')) - .unwrap(); + let re = + Regex::new(r"^\w*((?:[\?*]|\[\d+(?:-\d+)?\]|\[[a-zA-Z]+(?:-[a-zA-Z]+)?\])+)\w*$").unwrap(); + let caps = re.captures(spec).unwrap(); + let spec = caps.get(0).unwrap(); + let token = caps.get(1).unwrap(); + let li = token.start(); + let ri = spec.end() - token.end(); (li, ri) }