pub fn tag<T, Input, Error: ParseError<Input>, const STREAMING: bool>(
tag: T
) -> impl Fn(Input) -> IResult<Input, <Input as IntoOutput>::Output, Error>where
Input: InputTake + InputLength + Compare<T> + InputIsStreaming<STREAMING> + IntoOutput,
T: InputLength + Clone,
Expand description
Recognizes a pattern
The input data will be compared to the tag combinator’s argument and will return the part of the input that matches the argument
It will return Err(Err::Error((_, ErrorKind::Tag)))
if the input doesn’t match the pattern
Note: Parser
is implemented for strings and byte strings as a convenience (complete
only)
Example
use nom8::bytes::tag;
fn parser(s: &str) -> IResult<&str, &str> {
tag("Hello")(s)
}
assert_eq!(parser("Hello, World!"), Ok((", World!", "Hello")));
assert_eq!(parser("Something"), Err(Err::Error(Error::new("Something", ErrorKind::Tag))));
assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
use nom8::bytes::tag;
fn parser(s: Streaming<&str>) -> IResult<Streaming<&str>, &str> {
tag("Hello")(s)
}
assert_eq!(parser(Streaming("Hello, World!")), Ok((Streaming(", World!"), "Hello")));
assert_eq!(parser(Streaming("Something")), Err(Err::Error(Error::new(Streaming("Something"), ErrorKind::Tag))));
assert_eq!(parser(Streaming("S")), Err(Err::Error(Error::new(Streaming("S"), ErrorKind::Tag))));
assert_eq!(parser(Streaming("H")), Err(Err::Incomplete(Needed::new(4))));