mirror of
https://github.com/theryangeary/choose
synced 2024-11-10 13:34:13 +00:00
Add regex matching with field separator
This commit is contained in:
parent
5a5a77e88f
commit
da7a536fa6
1 changed files with 16 additions and 1 deletions
17
src/main.rs
17
src/main.rs
|
@ -16,7 +16,22 @@ enum Choice {
|
|||
|
||||
impl Choice {
|
||||
fn print_choice(&self, line: &String, opt: &Opt) {
|
||||
let words = line.split_whitespace().into_iter().enumerate();
|
||||
let re = Regex::new(match &opt.field_separator {
|
||||
Some(s) => s,
|
||||
None => "[[:space:]]",
|
||||
})
|
||||
.unwrap_or_else(|_| {
|
||||
panic!(
|
||||
"Failed to compile regular expression: {:?}",
|
||||
opt.field_separator
|
||||
)
|
||||
});
|
||||
|
||||
let words = re
|
||||
.split(line)
|
||||
.into_iter()
|
||||
.filter(|s| !s.is_empty())
|
||||
.enumerate();
|
||||
|
||||
match self {
|
||||
Choice::Field(i) => {
|
||||
|
|
Loading…
Reference in a new issue