[][src]Function nom::bytes::complete::escaped

pub fn escaped<Input, Error, F, G, O1, O2>(
    normal: F,
    control_char: char,
    escapable: G
) -> impl Fn(Input) -> IResult<Input, Input, Error> where
    Input: Clone + Offset + InputLength + InputTake + InputTakeAtPosition + Slice<RangeFrom<usize>> + InputIter,
    <Input as InputIter>::Item: AsChar,
    F: Fn(Input) -> IResult<Input, O1, Error>,
    G: Fn(Input) -> IResult<Input, O2, Error>,
    Error: ParseError<Input>, 

Matches a byte string with escaped characters.

  • The first argument matches the normal characters (it must not accept the control character),
  • the second argument is the control character (like \ in most languages),
  • the third argument matches the escaped characters

Example

use nom::bytes::complete::escaped;
use nom::character::complete::one_of;

fn esc(s: &str) -> IResult<&str, &str> {
  escaped(digit1, '\\', one_of(r#""n\"#))(s)
}

assert_eq!(esc("123;"), Ok((";", "123")));
assert_eq!(esc(r#"12\"34;"#), Ok((";", r#"12\"34"#)));