From a6e48aee6aa8cd09a0f41fe392394ec4f56de230 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 6 Apr 2020 21:09:06 -0400 Subject: [PATCH] Switch to escaped_transform to unescape the text. --- src/parser/parser.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 68d0778..5121aa9 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -1,5 +1,6 @@ use nom::branch::alt; use nom::bytes::complete::escaped; +use nom::bytes::complete::escaped_transform; use nom::bytes::complete::is_a; use nom::bytes::complete::is_not; use nom::bytes::complete::tag; @@ -328,10 +329,10 @@ pub fn template(i: &str) -> IResult<&str, Template> { Ok((remaining, Template { contents: contents })) } -fn quoted_string(i: &str) -> IResult<&str, &str> { +fn quoted_string(i: &str) -> IResult<&str, String> { delimited( tag(r#"""#), - escaped(is_not(r#"\""#), '\\', one_of(r#"\""#)), + escaped_transform(is_not(r#"\""#), '\\', one_of(r#"\""#)), tag(r#"""#), )(i) } @@ -614,6 +615,9 @@ mod tests { #[test] fn test_temp_string() { - assert_eq!(quoted_string(r#""foo\"bar""#), Ok(("", r#"foo\"bar"#))); + assert_eq!( + quoted_string(r#""foo\"bar""#), + Ok(("", r#"foo"bar"#.to_owned())) + ); } }