mmv_lib/
matcher.rs

1#![forbid(unsafe_code)]
2
3use crate::error_handler::Error;
4use crate::matches::ParsedFileName;
5use crate::input_parser::ParsedPattern;
6
7pub fn match_pattern_with_file_names(
8    pattern: &ParsedPattern,
9    file_names: &Vec<String>,
10) -> Result<Vec<ParsedFileName>, Error> {
11    let mut matching_files = Vec::<ParsedFileName>::new();
12
13    for file_name in file_names {
14        match pattern.match_to_pattern(file_name) {
15            Err(_) => continue,
16            Ok(fragments) => matching_files.push(ParsedFileName::new(file_name, fragments)),
17        }
18    }
19
20    match matching_files.is_empty() {
21        true => Err(Error::NoMatchingFilesFound),
22        false => Ok(matching_files),
23    }
24}