diff --git a/src/ascii/mod.rs b/src/ascii/mod.rs index fdfa236a..824baee6 100644 --- a/src/ascii/mod.rs +++ b/src/ascii/mod.rs @@ -132,7 +132,7 @@ where I: StreamIsPartial, I: Stream, I: Compare<&'static str>, - I: FindSlice<(u8, u8)>, + I: FindSlice<(char, char)>, ::Token: AsChar + Clone, { trace("till_line_ending", move |input: &mut I| { @@ -152,10 +152,10 @@ where I: StreamIsPartial, I: Stream, I: Compare<&'static str>, - I: FindSlice<(u8, u8)>, + I: FindSlice<(char, char)>, ::Token: AsChar + Clone, { - let res = match take_until::<_, _, ()>(0.., (b'\r', b'\n')).parse_next(input) { + let res = match take_until::<_, _, ()>(0.., ('\r', '\n')).parse_next(input) { Ok(slice) => slice, Err(ErrMode::Incomplete(err)) => { return Err(ErrMode::Incomplete(err)); diff --git a/src/stream/mod.rs b/src/stream/mod.rs index b1ad69cd..87ff1580 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -2194,20 +2194,6 @@ impl<'a, 'b> Compare> for &'a str { } } -impl<'a> Compare for &'a str { - #[inline(always)] - fn compare(&self, t: u8) -> CompareResult { - self.as_bytes().compare(t) - } -} - -impl<'a> Compare> for &'a str { - #[inline(always)] - fn compare(&self, t: AsciiCaseless) -> CompareResult { - self.as_bytes().compare(t) - } -} - impl<'a> Compare for &'a str { #[inline(always)] fn compare(&self, t: char) -> CompareResult { @@ -2222,20 +2208,6 @@ impl<'a> Compare> for &'a str { } } -impl<'a, 'b> Compare<&'b [u8]> for &'a str { - #[inline(always)] - fn compare(&self, t: &'b [u8]) -> CompareResult { - self.as_bytes().compare(t) - } -} - -impl<'a, 'b> Compare> for &'a str { - #[inline(always)] - fn compare(&self, t: AsciiCaseless<&'b [u8]>) -> CompareResult { - self.as_bytes().compare(t) - } -} - impl<'a, T> Compare for &'a Bytes where &'a [u8]: Compare, @@ -2340,6 +2312,48 @@ impl<'i, 's> FindSlice<(&'s [u8], &'s [u8], &'s [u8])> for &'i [u8] { } } +impl<'i> FindSlice for &'i [u8] { + #[inline(always)] + fn find_slice(&self, substr: char) -> Option> { + let mut b = [0; 4]; + let substr = substr.encode_utf8(&mut b); + self.find_slice(&*substr) + } +} + +impl<'i> FindSlice<(char,)> for &'i [u8] { + #[inline(always)] + fn find_slice(&self, substr: (char,)) -> Option> { + let mut b = [0; 4]; + let substr0 = substr.0.encode_utf8(&mut b); + self.find_slice((&*substr0,)) + } +} + +impl<'i> FindSlice<(char, char)> for &'i [u8] { + #[inline(always)] + fn find_slice(&self, substr: (char, char)) -> Option> { + let mut b = [0; 4]; + let substr0 = substr.0.encode_utf8(&mut b); + let mut b = [0; 4]; + let substr1 = substr.1.encode_utf8(&mut b); + self.find_slice((&*substr0, &*substr1)) + } +} + +impl<'i> FindSlice<(char, char, char)> for &'i [u8] { + #[inline(always)] + fn find_slice(&self, substr: (char, char, char)) -> Option> { + let mut b = [0; 4]; + let substr0 = substr.0.encode_utf8(&mut b); + let mut b = [0; 4]; + let substr1 = substr.1.encode_utf8(&mut b); + let mut b = [0; 4]; + let substr2 = substr.2.encode_utf8(&mut b); + self.find_slice((&*substr0, &*substr1, &*substr2)) + } +} + impl<'i> FindSlice for &'i [u8] { #[inline(always)] fn find_slice(&self, substr: u8) -> Option> { @@ -2409,7 +2423,7 @@ impl<'i, 's> FindSlice<(&'s str, &'s str, &'s str)> for &'i [u8] { impl<'i, 's> FindSlice<&'s str> for &'i str { #[inline(always)] fn find_slice(&self, substr: &'s str) -> Option> { - self.as_bytes().find_slice(substr.as_bytes()) + self.as_bytes().find_slice(substr) } } @@ -2440,70 +2454,28 @@ impl<'i, 's> FindSlice<(&'s str, &'s str, &'s str)> for &'i str { impl<'i> FindSlice for &'i str { #[inline(always)] fn find_slice(&self, substr: char) -> Option> { - let mut b = [0; 4]; - let substr = substr.encode_utf8(&mut b); - self.find_slice(&*substr) + self.as_bytes().find_slice(substr) } } impl<'i> FindSlice<(char,)> for &'i str { #[inline(always)] fn find_slice(&self, substr: (char,)) -> Option> { - let mut b = [0; 4]; - let substr0 = substr.0.encode_utf8(&mut b); - self.find_slice((&*substr0,)) + self.as_bytes().find_slice(substr) } } impl<'i> FindSlice<(char, char)> for &'i str { #[inline(always)] fn find_slice(&self, substr: (char, char)) -> Option> { - let mut b = [0; 4]; - let substr0 = substr.0.encode_utf8(&mut b); - let mut b = [0; 4]; - let substr1 = substr.1.encode_utf8(&mut b); - self.find_slice((&*substr0, &*substr1)) + self.as_bytes().find_slice(substr) } } impl<'i> FindSlice<(char, char, char)> for &'i str { #[inline(always)] fn find_slice(&self, substr: (char, char, char)) -> Option> { - let mut b = [0; 4]; - let substr0 = substr.0.encode_utf8(&mut b); - let mut b = [0; 4]; - let substr1 = substr.1.encode_utf8(&mut b); - let mut b = [0; 4]; - let substr2 = substr.2.encode_utf8(&mut b); - self.find_slice((&*substr0, &*substr1, &*substr2)) - } -} - -impl<'i> FindSlice for &'i str { - #[inline(always)] - fn find_slice(&self, substr: u8) -> Option> { - self.find_slice(substr.as_char()) - } -} - -impl<'i> FindSlice<(u8,)> for &'i str { - #[inline(always)] - fn find_slice(&self, substr: (u8,)) -> Option> { - self.find_slice((substr.0.as_char(),)) - } -} - -impl<'i> FindSlice<(u8, u8)> for &'i str { - #[inline(always)] - fn find_slice(&self, substr: (u8, u8)) -> Option> { - self.find_slice((substr.0.as_char(), substr.1.as_char())) - } -} - -impl<'i> FindSlice<(u8, u8, u8)> for &'i str { - #[inline(always)] - fn find_slice(&self, substr: (u8, u8, u8)) -> Option> { - self.find_slice((substr.0.as_char(), substr.1.as_char(), substr.2.as_char())) + self.as_bytes().find_slice(substr) } }