1use crate::util;
2
3pub mod fallback;
5#[cfg(feature = "simd")]
7pub mod nightly;
8#[cfg(not(feature = "simd"))]
10pub mod stable;
11
12macro_rules! decide {
13 ($nightly:expr, $stable:expr) => {{
14 #[cfg(feature = "simd")]
15 {
16 $nightly
17 }
18 #[cfg(not(feature = "simd"))]
19 {
20 $stable
21 }
22 }};
23}
24
25#[inline]
27pub fn is_closing(needle: u8) -> bool {
28 decide!(nightly::is_closing(needle), stable::is_closing(needle))
29}
30
31#[inline]
33pub fn search_non_ident(haystack: &[u8]) -> Option<usize> {
34 decide!(
35 nightly::search_non_ident(haystack),
36 fallback::search_non_ident(haystack)
37 )
38}
39
40#[inline]
42pub fn find4(haystack: &[u8], needle: [u8; 4]) -> Option<usize> {
43 decide!(
44 nightly::find4(haystack, needle),
45 stable::find_multi(haystack, needle)
46 )
47}
48
49#[inline]
51pub fn find(haystack: &[u8], needle: u8) -> Option<usize> {
52 decide!(
53 nightly::find(haystack, needle),
54 stable::find(haystack, needle)
55 )
56}
57
58pub fn matches_case_insensitive<const N: usize>(haystack: &[u8], needle: [u8; N]) -> bool {
60 if haystack.len() != N {
61 return false;
62 }
63
64 let mut mask = true;
67 for i in 0..N {
68 mask &= util::to_lower(haystack[i]) == needle[i];
69 }
70 mask
71}