Slightly edit module matching logic for conciseness/clarity

Also allow using identifier names directly as shorthand, without
   surrounding .{ ... }
This commit is contained in:
KtorZ 2023-01-10 18:41:02 +01:00
parent 99ec0ff6b0
commit e06bbc4e73
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 15 additions and 21 deletions

View File

@ -716,7 +716,11 @@ where
.map(|match_test| { .map(|match_test| {
let mut match_split_dot = match_test.split('.'); let mut match_split_dot = match_test.split('.');
let match_module = match_split_dot.next().unwrap_or(""); let match_module = if match_test.contains('.') {
match_split_dot.next().unwrap_or("")
} else {
""
};
let match_names = match_split_dot.next().map(|names| { let match_names = match_split_dot.next().map(|names| {
let names = names.replace(&['{', '}'][..], ""); let names = names.replace(&['{', '}'][..], "");
@ -733,29 +737,19 @@ where
scripts scripts
.into_iter() .into_iter()
.filter(|script| -> bool { .filter(|script| -> bool {
match_tests.iter().any(|(match_module, match_names)| { match_tests.iter().any(|(module, names)| {
let matches_name = || { let matched_module = module == &"" || script.module.contains(module);
matches!(match_names, Some(match_names) if match_names
.iter()
.any(|name| if exact_match {
name == &script.name
} else {
script.name.contains(name)
}
))
};
if *match_module == script.module || script.module.contains(match_module) { let matched_name = matches!(names, Some(names) if names
if match_names.is_some() { .iter()
matches_name() .any(|name| if exact_match {
name == &script.name
} else { } else {
true script.name.contains(name)
} }
} else if match_names.is_some() && match_module == &"" { ));
matches_name()
} else { matched_module && matched_name
false
}
}) })
}) })
.collect::<Vec<Script>>() .collect::<Vec<Script>>()