diff options
Diffstat (limited to 'src/modes/edit/regex.rs')
-rw-r--r-- | src/modes/edit/regex.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/modes/edit/regex.rs b/src/modes/edit/regex.rs new file mode 100644 index 0000000..a91674b --- /dev/null +++ b/src/modes/edit/regex.rs @@ -0,0 +1,23 @@ +use std::path::Path; + +use anyhow::Result; + +use crate::{common::filename_from_path, modes::edit::Flagged}; + +/// Flag every file matching a typed regex in current directory. +/// +/// # Errors +/// +/// It may fail if the `input_string` can't be parsed as a regex expression. +/// It may also fail if a file in the directory has a filename which can't be decoded as utf-8. +pub fn regex_matcher(input_string: &str, paths: &[&Path], flagged: &mut Flagged) -> Result<()> { + flagged.clear(); + let re = regex::Regex::new(input_string)?; + for path in paths { + if re.is_match(filename_from_path(path)?) { + flagged.push(path.to_path_buf()); + } + } + + Ok(()) +} |