[−][src]Macro nom::escaped_transform
escaped_transform!(&[T] -> IResult<&[T], &[T]>, T, &[T] -> IResult<&[T], &[T]>) => &[T] -> IResult<&[T], Vec<T>>
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)
WARNING: if you do not use the verbose-errors
feature, this combinator will currently fail to build
because of a type inference error
Example
ⓘThis example is not tested
fn to_s(i:Vec<u8>) -> String { String::from_utf8_lossy(&i).into_owned() } named!(transform < String >, map!( escaped_transform!(call!(alpha), '\\', alt!( tag!("\\") => { |_| &b"\\"[..] } | tag!("\"") => { |_| &b"\""[..] } | tag!("n") => { |_| &b"\n"[..] } ) ), to_s ) ); assert_eq!(transform(&b"ab\\\"cd"[..]), Ok((&b""[..], String::from("ab\"cd"))));