1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#[inline(always)]
pub(crate) fn get_file_name(path: &[u8]) -> &[u8] {
if let Some(ofs) = path.iter().rposition(|&b| b == b'/' || b == b'\\') {
&path[ofs + 1..]
} else {
path
}
}
#[inline(always)]
pub(crate) fn get_extension(file_name: &[u8]) -> &[u8] {
if let Some(ofs) = file_name.iter().rposition(|&b| b == b'.') {
&file_name[ofs + 1..]
} else {
&[]
}
}
pub(crate) fn contains_uppercase(buf: &[u8]) -> bool {
for b in buf {
if *b >= b'A' && *b <= b'Z' {
return true;
}
}
false
}
pub(crate) fn copy_lowercase<'a>(source: &[u8], output: &'a mut Vec<u8>) -> &'a [u8] {
output.clear();
output.extend_from_slice(source);
output.make_ascii_lowercase();
output.as_slice()
}
/// ASCII-lowercases a `'static` pattern for the matcher.
///
/// Already-lowercase strings are returned as-is (no allocation).
/// Mixed-case patterns are leaked once at filter build time.
pub(crate) fn ascii_lower_static(s: &'static str) -> &'static [u8] {
let bytes = s.as_bytes();
if !contains_uppercase(bytes) {
bytes
} else {
let mut owned = bytes.to_vec();
owned.make_ascii_lowercase();
Box::leak(owned.into_boxed_slice())
}
}