Skip to content

Commit

Permalink
fix: Deprecate tag_no_case
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 1, 2023
1 parent 809b1bf commit 0da4253
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/ascii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,7 @@ where
}

#[allow(clippy::trait_duplication_in_bounds)] // HACK: clippy 1.64.0 bug
#[allow(deprecated)]
fn recognize_float_or_exceptions<I, E: ParserError<I>>(
input: &mut I,
) -> PResult<<I as Stream>::Slice, E>
Expand Down
3 changes: 1 addition & 2 deletions src/combinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
//! |---|---|---|---|---|---|
//! | [`one_of`][crate::token::one_of] | `one_of(['a', 'b', 'c'])` | `"abc"` | `"bc"` | `Ok('a')` |Matches one of the provided characters (works with non ASCII characters too)|
//! | [`none_of`][crate::token::none_of] | `none_of(['a', 'b', 'c'])` | `"xyab"` | `"yab"` | `Ok('x')` |Matches anything but the provided characters|
//! | [`tag`][crate::token::tag] | `"hello"` | `"hello world"` | `" world"` | `Ok("hello")` |Recognizes a specific suite of characters or bytes|
//! | [`tag_no_case`][crate::token::tag_no_case] | `tag_no_case("hello")` | `"HeLLo World"` | `" World"` | `Ok("HeLLo")` |Case insensitive comparison. Note that case insensitive comparison is not well defined for unicode, and that you might have bad surprises|
//! | [`tag`][crate::token::tag] | `"hello"` | `"hello world"` | `" world"` | `Ok("hello")` |Recognizes a specific suite of characters or bytes (see also [`Caseless`][crate::ascii::Caseless])|
//! | [`take`][crate::token::take] | `take(4)` | `"hello"` | `"o"` | `Ok("hell")` |Takes a specific number of bytes or characters|
//! | [`take_while`][crate::token::take_while] | `take_while(0.., is_alphabetic)` | `"abc123"` | `"123"` | `Ok("abc")` |Returns the longest list of bytes for which the provided pattern matches.|
//! | [`take_till0`][crate::token::take_till0] | `take_till0(is_alphabetic)` | `"123abc"` | `"abc"` | `Ok("123")` |Returns the longest list of bytes or characters until the provided pattern matches. `take_till1` does the same, but must return at least one character. This is the reverse behaviour from `take_while`: `take_till(f)` is equivalent to `take_while(0.., \|c\| !f(c))`|
Expand Down
18 changes: 18 additions & 0 deletions src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,7 @@ pub trait Compare<T> {
/// by lowercasing both strings and comparing
/// the result. This is a temporary solution until
/// a better one appears
#[deprecated(since = "0.5.20", note = "Replaced with `compare(ascii::Caseless(_))`")]
fn compare_no_case(&self, t: T) -> CompareResult;
}

Expand Down Expand Up @@ -1617,6 +1618,7 @@ impl<'a, 'b> Compare<&'b [u8]> for &'a [u8] {
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: &'b [u8]) -> CompareResult {
self.compare(AsciiCaseless(t))
}
Expand All @@ -1639,6 +1641,7 @@ impl<'a, 'b> Compare<AsciiCaseless<&'b [u8]>> for &'a [u8] {
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: AsciiCaseless<&'b [u8]>) -> CompareResult {
self.compare(t)
}
Expand All @@ -1651,6 +1654,7 @@ impl<'a, const LEN: usize> Compare<[u8; LEN]> for &'a [u8] {
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: [u8; LEN]) -> CompareResult {
self.compare_no_case(&t[..])
}
Expand All @@ -1663,6 +1667,7 @@ impl<'a, const LEN: usize> Compare<AsciiCaseless<[u8; LEN]>> for &'a [u8] {
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: AsciiCaseless<[u8; LEN]>) -> CompareResult {
self.compare_no_case(AsciiCaseless(&t.0[..]))
}
Expand All @@ -1675,6 +1680,7 @@ impl<'a, 'b, const LEN: usize> Compare<&'b [u8; LEN]> for &'a [u8] {
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: &'b [u8; LEN]) -> CompareResult {
self.compare_no_case(&t[..])
}
Expand All @@ -1687,6 +1693,7 @@ impl<'a, 'b, const LEN: usize> Compare<AsciiCaseless<&'b [u8; LEN]>> for &'a [u8
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: AsciiCaseless<&'b [u8; LEN]>) -> CompareResult {
self.compare_no_case(AsciiCaseless(&t.0[..]))
}
Expand All @@ -1698,6 +1705,7 @@ impl<'a, 'b> Compare<&'b str> for &'a [u8] {
self.compare(t.as_bytes())
}
#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: &'b str) -> CompareResult {
self.compare_no_case(t.as_bytes())
}
Expand All @@ -1709,6 +1717,7 @@ impl<'a, 'b> Compare<AsciiCaseless<&'b str>> for &'a [u8] {
self.compare(AsciiCaseless(t.0.as_bytes()))
}
#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: AsciiCaseless<&'b str>) -> CompareResult {
self.compare_no_case(AsciiCaseless(t.0.as_bytes()))
}
Expand All @@ -1721,6 +1730,7 @@ impl<'a, 'b> Compare<&'b str> for &'a str {
}

#[inline]
#[allow(deprecated)]
fn compare_no_case(&self, t: &'b str) -> CompareResult {
self.compare(AsciiCaseless(t))
}
Expand All @@ -1747,6 +1757,7 @@ impl<'a, 'b> Compare<AsciiCaseless<&'b str>> for &'a str {
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: AsciiCaseless<&'b str>) -> CompareResult {
self.compare(t)
}
Expand All @@ -1758,6 +1769,7 @@ impl<'a, 'b> Compare<&'b [u8]> for &'a str {
AsBStr::as_bstr(self).compare(t)
}
#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: &'b [u8]) -> CompareResult {
AsBStr::as_bstr(self).compare_no_case(t)
}
Expand All @@ -1769,6 +1781,7 @@ impl<'a, 'b> Compare<AsciiCaseless<&'b [u8]>> for &'a str {
AsBStr::as_bstr(self).compare(t)
}
#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: AsciiCaseless<&'b [u8]>) -> CompareResult {
AsBStr::as_bstr(self).compare_no_case(t)
}
Expand All @@ -1785,6 +1798,7 @@ where
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: T) -> CompareResult {
let bytes = (*self).as_bytes();
bytes.compare_no_case(t)
Expand All @@ -1802,6 +1816,7 @@ where
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: T) -> CompareResult {
let bytes = (*self).as_bytes();
bytes.compare_no_case(t)
Expand All @@ -1818,6 +1833,7 @@ where
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, other: U) -> CompareResult {
self.input.compare_no_case(other)
}
Expand All @@ -1833,6 +1849,7 @@ where
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, other: U) -> CompareResult {
self.input.compare_no_case(other)
}
Expand All @@ -1848,6 +1865,7 @@ where
}

#[inline(always)]
#[allow(deprecated)]
fn compare_no_case(&self, t: T) -> CompareResult {
self.input.compare_no_case(t)
}
Expand Down
2 changes: 2 additions & 0 deletions src/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ where
#[doc(alias = "literal")]
#[doc(alias = "bytes")]
#[doc(alias = "just")]
#[deprecated(since = "0.5.20", note = "Replaced with `tag(ascii::Caseless(_))`")]
pub fn tag_no_case<T, I, Error: ParserError<I>>(
tag: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
Expand All @@ -236,6 +237,7 @@ where
})
}

#[allow(deprecated)]
fn tag_no_case_<T, I, Error: ParserError<I>, const PARTIAL: bool>(
i: &mut I,
t: T,
Expand Down
5 changes: 3 additions & 2 deletions src/token/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::*;
#[cfg(feature = "std")]
use proptest::prelude::*;

use crate::ascii::Caseless;
use crate::binary::length_data;
use crate::combinator::delimited;
use crate::error::ErrMode;
Expand Down Expand Up @@ -619,7 +620,7 @@ fn partial_length_bytes() {
#[test]
fn partial_case_insensitive() {
fn test(i: Partial<&[u8]>) -> IResult<Partial<&[u8]>, &[u8]> {
tag_no_case("ABcd").parse_peek(i)
tag(Caseless("ABcd")).parse_peek(i)
}
assert_eq!(
test(Partial::new(&b"aBCdefgh"[..])),
Expand Down Expand Up @@ -653,7 +654,7 @@ fn partial_case_insensitive() {
);

fn test2(i: Partial<&str>) -> IResult<Partial<&str>, &str> {
tag_no_case("ABcd").parse_peek(i)
tag(Caseless("ABcd")).parse_peek(i)
}
assert_eq!(
test2(Partial::new("aBCdefgh")),
Expand Down
5 changes: 3 additions & 2 deletions tests/testsuite/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#[cfg(test)]
mod test {
use winnow::ascii::Caseless;
use winnow::Parser;
use winnow::Partial;
#[cfg(feature = "alloc")]
use winnow::{combinator::alt, combinator::repeat, token::tag_no_case};
use winnow::{combinator::alt, combinator::repeat, token::tag};
use winnow::{
error::ErrMode,
error::{ErrorKind, InputError},
Expand Down Expand Up @@ -74,7 +75,7 @@ mod test {
#[test]
fn tag_case_insensitive_str() {
fn test(i: &str) -> IResult<&str, &str> {
tag_no_case("ABcd").parse_peek(i)
tag(Caseless("ABcd")).parse_peek(i)
}
assert_eq!(test("aBCdefgh"), Ok(("efgh", "aBCd")));
assert_eq!(test("abcdefgh"), Ok(("efgh", "abcd")));
Expand Down

0 comments on commit 0da4253

Please sign in to comment.