Merge branch 'quoted_strings'

This commit is contained in:
Tom Alexander 2020-04-06 21:26:29 -04:00
commit c6f43820ca
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1,5 +1,8 @@
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;
use nom::bytes::complete::take_until;
use nom::character::complete::one_of;
@ -326,6 +329,14 @@ pub fn template(i: &str) -> IResult<&str, Template> {
Ok((remaining, Template { contents: contents }))
}
fn quoted_string(i: &str) -> IResult<&str, String> {
delimited(
tag(r#"""#),
escaped_transform(is_not(r#"\""#), '\\', one_of(r#"\""#)),
tag(r#"""#),
)(i)
}
#[cfg(test)]
mod tests {
use super::*;
@ -601,4 +612,12 @@ mod tests {
))
);
}
#[test]
fn test_quoted_string() {
assert_eq!(
quoted_string(r#""foo\"bar\\baz""#),
Ok(("", r#"foo"bar\baz"#.to_owned()))
);
}
}