Function winnow::bytes::streaming::escaped_transform
source · pub fn escaped_transform<I, Error, F, G, Output>(
normal: F,
control_char: char,
transform: G
) -> impl FnMut(I) -> IResult<I, Output, Error>where
I: Stream + Offset,
<I as Stream>::Token: AsChar,
Output: Accumulate<<I as Stream>::Slice>,
F: Parser<I, <I as Stream>::Slice, Error>,
G: Parser<I, <I as Stream>::Slice, Error>,
Error: ParseError<I>,👎Deprecated since 0.1.0: Replaced with <code>winnow::character::escaped_transform</code> with input wrapped in <code>winnow::Partial</code>
Expand description
Matches a byte string with escaped characters.
- The first argument matches the normal characters (it must not match the control character)
- The second argument is the control character (like
\in most languages) - The third argument matches the escaped characters and transforms them
As an example, the chain abc\tdef could be abc def (it also consumes the control character)
use winnow::bytes::streaming::{escaped_transform, tag};
use winnow::character::streaming::alpha1;
use winnow::branch::alt;
use winnow::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"))));WARNING: Deprecated, replaced with winnow::character::escaped_transform with input wrapped in winnow::Partial