use crate::cli::verify::FunctionToVerify;
pub fn filter_functions(
functions: Vec<FunctionToVerify>,
subsystem: Option<&str>,
name: Option<&str>,
sections: &[String],
) -> Vec<FunctionToVerify> {
functions
.into_iter()
.filter(|f| {
if let Some(subsys) = subsystem {
if !matches_subsystem(&f.file_path, subsys) {
return false;
}
}
if let Some(name_pattern) = name {
if !matches_name(&f.function_name, name_pattern) {
return false;
}
}
if !sections.is_empty() {
if let Some(ref section) = f.section {
if !sections.contains(section) {
return false;
}
} else {
return false; }
}
true
})
.collect()
}
fn matches_subsystem(file_path: &std::path::Path, subsystem: &str) -> bool {
let path_str = file_path.to_string_lossy();
path_str.contains(subsystem)
}
fn matches_name(function_name: &str, pattern: &str) -> bool {
if pattern.contains('*') {
let _regex_pattern = pattern.replace('*', ".*");
function_name.contains(&pattern.replace('*', ""))
} else {
function_name == pattern
}
}