diff options
| author | Fuwn <[email protected]> | 2025-06-07 13:34:17 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-06-07 13:34:17 +0000 |
| commit | 22bce5a842dc365a5a18644d0fbdcc75e6aa5d5e (patch) | |
| tree | 17f02d84656a586e826fae5c2802644a045e6b13 /src/url.rs | |
| parent | chore: Bump version patch (diff) | |
| download | september-22bce5a842dc365a5a18644d0fbdcc75e6aa5d5e.tar.xz september-22bce5a842dc365a5a18644d0fbdcc75e6aa5d5e.zip | |
feat!: Overhaul KEEP_GEMINI configuration option
Diffstat (limited to 'src/url.rs')
| -rw-r--r-- | src/url.rs | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -57,3 +57,45 @@ pub fn from_path( ) }) } + +pub fn matches_pattern(pattern: &str, path: &str) -> bool { + if !pattern.contains('*') { + return path == pattern; + } + + let parts: Vec<&str> = pattern.split('*').collect(); + let mut position = if pattern.starts_with('*') { + 0 + } else { + let first = parts.first().unwrap(); + + if !path.starts_with(first) { + return false; + } + + first.len() + }; + let before_last = parts.len().saturating_sub(1); + + for part in &parts[1..before_last] { + if part.is_empty() { + continue; + } + + if let Some(found) = path[position..].find(part) { + position += found + part.len(); + } else { + return false; + } + } + + if !pattern.ends_with('*') { + let last = parts.last().unwrap(); + + if !path[position..].ends_with(last) { + return false; + } + } + + true +} |