Function escaped_transform

fn escaped_transform<I, Error, F, G, ExtendItem, Output>(normal: F, control_char: char, transform: G) -> impl Parser<I, Output = Output, Error = Error>
where
    I: Clone + crate::traits::Offset + Input + crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
    <F as Parser<I>>::Output: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
    <G as Parser<I>>::Output: crate::traits::ExtendInto<Item = ExtendItem, Extender = Output>,
    <I as Input>::Item: crate::traits::AsChar,
    F: Parser<I, Error = Error>,
    G: Parser<I, Error = Error>,
    Error: ParseError<I>

Matches a byte string with escaped characters.

As an example, the chain abc\tdef could be abc def (it also consumes the control character)

# use nom::{Err, error::ErrorKind, Needed, IResult};
# use std::str::from_utf8;
use nom::bytes::streaming::{escaped_transform, tag};
use nom::character::streaming::alpha1;
use nom::branch::alt;
use nom::combinator::value;

fn parser(input: &str) -> IResult<&str, String> {
  escaped_transform(
    alpha1,
    '\\',
    alt((
      value("\\", tag("\\")),
      value("\"", tag("\"")),
      value("\n", tag("n")),
    ))
  )(input)
}

assert_eq!(parser("ab\\\"cd\""), Ok(("\"", String::from("ab\"cd"))));