rustmax::nom::bytes::complete

Function escaped

Source
pub fn escaped<'a, I, Error, F, G>(
    normal: F,
    control_char: char,
    escapable: G,
) -> impl FnMut(I)
where I: Clone + Offset + Input + 'a, <I as Input>::Item: AsChar, F: Parser<I, Error = Error>, G: Parser<I, Error = Error>, Error: ParseError<I>,
Expand description

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"#)));