From 3e5eb2ae7b3eefcbd0a73e60fdd611d319282625 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Tue, 12 Dec 2023 01:01:35 -0500 Subject: [PATCH] contains_all_in_order --- src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 2123ad4..8cf0eae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1155,6 +1155,17 @@ fn parse_filter(filter: &str) -> egui_file::Filter { let name = p.file_name().unwrap_or_default().to_string_lossy(); variants .iter() - .any(|pieces| pieces.iter().all(|piece| name.contains(piece))) + .any(|pieces| contains_all_in_order(&name, &pieces)) }) } + +fn contains_all_in_order(haystack: &str, needles: &[String]) -> bool { + let mut hay: &str = haystack; + for piece in needles { + let Some((_, rst)) = hay.split_once(piece) else { + return false; + }; + hay = rst; + } + true +}