Matches a pattern where `*` stands for any run of characters.
(pattern: &str, text: &str)
| 153 | |
| 154 | /// Matches a pattern where `*` stands for any run of characters. |
| 155 | fn matches(pattern: &str, text: &str) -> bool { |
| 156 | let mut parts = pattern.split('*'); |
| 157 | let Some(mut rest) = text.strip_prefix(parts.next().unwrap_or_default()) else { |
| 158 | return false; |
| 159 | }; |
| 160 | let Some(mut part) = parts.next() else { return rest.is_empty() }; |
| 161 | for next in parts { |
| 162 | let Some(index) = rest.find(part) else { return false }; |
| 163 | rest = &rest[index + part.len()..]; |
| 164 | part = next; |
| 165 | } |
| 166 | rest.ends_with(part) |
| 167 | } |