Function winnow::token::tag_no_case

source ·
pub fn tag_no_case<T, I, Error: ParserError<I>>(
    tag: T,
) -> impl Parser<I, <I as Stream>::Slice, Error>
Expand description

Recognizes a case insensitive literal.

The input data will be compared to the tag combinator’s argument and will return the part of the input that matches the argument with no regard to case.

It will return Err(ErrMode::Backtrack(InputError::new(_, ErrorKind::Tag))) if the input doesn’t match the pattern.

§Example

use winnow::token::tag_no_case;

fn parser(s: &str) -> IResult<&str, &str> {
  tag_no_case("hello").parse_peek(s)
}

assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
assert_eq!(parser("hello, World!"), Ok((", World!", "hello")));
assert_eq!(parser("HeLlO, World!"), Ok((", World!", "HeLlO")));
assert_eq!(parser("Something"), Err(ErrMode::Backtrack(InputError::new("Something", ErrorKind::Tag))));
assert_eq!(parser(""), Err(ErrMode::Backtrack(InputError::new("", ErrorKind::Tag))));
use winnow::token::tag_no_case;

fn parser(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
  tag_no_case("hello").parse_peek(s)
}

assert_eq!(parser(Partial::new("Hello, World!")), Ok((Partial::new(", World!"), "Hello")));
assert_eq!(parser(Partial::new("hello, World!")), Ok((Partial::new(", World!"), "hello")));
assert_eq!(parser(Partial::new("HeLlO, World!")), Ok((Partial::new(", World!"), "HeLlO")));
assert_eq!(parser(Partial::new("Something")), Err(ErrMode::Backtrack(InputError::new(Partial::new("Something"), ErrorKind::Tag))));
assert_eq!(parser(Partial::new("")), Err(ErrMode::Incomplete(Needed::new(5))));