1 | #![allow (dead_code)] |
2 | |
3 | pub fn memchr(n1: u8, haystack: &[u8]) -> Option<usize> { |
4 | haystack.iter().position(|&b: u8| b == n1) |
5 | } |
6 | |
7 | pub fn memchr2(n1: u8, n2: u8, haystack: &[u8]) -> Option<usize> { |
8 | haystack.iter().position(|&b: u8| b == n1 || b == n2) |
9 | } |
10 | |
11 | pub fn memchr3(n1: u8, n2: u8, n3: u8, haystack: &[u8]) -> Option<usize> { |
12 | haystack.iter().position(|&b: u8| b == n1 || b == n2 || b == n3) |
13 | } |
14 | |
15 | pub fn memrchr(n1: u8, haystack: &[u8]) -> Option<usize> { |
16 | haystack.iter().rposition(|&b: u8| b == n1) |
17 | } |
18 | |
19 | pub fn memrchr2(n1: u8, n2: u8, haystack: &[u8]) -> Option<usize> { |
20 | haystack.iter().rposition(|&b: u8| b == n1 || b == n2) |
21 | } |
22 | |
23 | pub fn memrchr3(n1: u8, n2: u8, n3: u8, haystack: &[u8]) -> Option<usize> { |
24 | haystack.iter().rposition(|&b: u8| b == n1 || b == n2 || b == n3) |
25 | } |
26 | |