Macro nom::escaped_transform [−][src]
This is supported on crate feature
alloc
only.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).
Example
fn to_s(i:Vec<u8>) -> String { String::from_utf8_lossy(&i).into_owned() } named!(transform < String >, map!( escaped_transform!(call!(alpha1), '\\', alt!( tag!("\\") => { |_| &b"\\"[..] } | tag!("\"") => { |_| &b"\""[..] } | tag!("n") => { |_| &b"\n"[..] } ) ), to_s ) ); assert_eq!(transform(&b"ab\\\"cd"[..]), Ok((&b""[..], String::from("ab\"cd"))));