mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-01-07 08:45:24 +02:00
Simplify solution to prefix matching.
This commit is contained in:
parent
2a92487bbd
commit
1fb0b0a46d
@ -15,25 +15,20 @@
|
||||
// ANCHOR: prefix_matches
|
||||
pub fn prefix_matches(prefix: &str, request_path: &str) -> bool {
|
||||
// ANCHOR_END: prefix_matches
|
||||
let mut prefixes = prefix
|
||||
.split('/')
|
||||
.map(|p| Some(p))
|
||||
.chain(std::iter::once(None));
|
||||
let mut request_paths = request_path
|
||||
let prefixes = prefix.split('/');
|
||||
let request_paths = request_path
|
||||
.split('/')
|
||||
.map(|p| Some(p))
|
||||
.chain(std::iter::once(None));
|
||||
|
||||
for (prefix, request_path) in prefixes.by_ref().zip(&mut request_paths) {
|
||||
match (prefix, request_path) {
|
||||
(Some(prefix), Some(request_path)) => {
|
||||
for (prefix, request_path) in prefixes.zip(request_paths) {
|
||||
match request_path {
|
||||
Some(request_path) => {
|
||||
if (prefix != "*") && (prefix != request_path) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
(Some(_), None) => return false,
|
||||
(None, None) => break,
|
||||
(None, Some(_)) => break,
|
||||
None => return false,
|
||||
}
|
||||
}
|
||||
true
|
||||
|
Loading…
Reference in New Issue
Block a user