Function winnow::ascii::take_escaped

source ·
pub fn take_escaped<'i, Input, Error, Normal, Escapable, NormalOutput, EscapableOutput>(
    normal: Normal,
    control_char: char,
    escapable: Escapable
) -> impl Parser<Input, <Input as Stream>::Slice, Error>
where Input: StreamIsPartial + Stream + Compare<char> + 'i, Normal: Parser<Input, NormalOutput, Error>, Escapable: Parser<Input, EscapableOutput, Error>, Error: ParserError<Input>,
Expand description

Recognize the input slice with escaped characters.

See also escaped_transform

§Example

use winnow::ascii::take_escaped;
use winnow::token::one_of;

fn esc(s: &str) -> IResult<&str, &str> {
  take_escaped(digit1, '\\', one_of(['"', 'n', '\\'])).parse_peek(s)
}

assert_eq!(esc("123;"), Ok((";", "123")));
assert_eq!(esc(r#"12\"34;"#), Ok((";", r#"12\"34"#)));
use winnow::ascii::take_escaped;
use winnow::token::one_of;

fn esc(s: Partial<&str>) -> IResult<Partial<&str>, &str> {
  take_escaped(digit1, '\\', one_of(['"', 'n', '\\'])).parse_peek(s)
}

assert_eq!(esc(Partial::new("123;")), Ok((Partial::new(";"), "123")));
assert_eq!(esc(Partial::new("12\\\"34;")), Ok((Partial::new(";"), "12\\\"34")));