Skip to content

Commit 0b12e6d

Browse files
committed
Escaped strings
1 parent bca6b48 commit 0b12e6d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/reader.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,21 @@ pub fn try_read_string(input: &str) -> IResult<&str, Value> {
379379

380380
let (rest_input, _) = quotation(input)?;
381381

382+
named!(escaped_string_parser<&str, String >, escaped_transform!(take_till1!(|ch| { ch == '\\' || ch == '\"'}), '\\', alt!(
383+
tag!("t") => { |_| "\t" } |
384+
tag!("b") => { |_| "\x08" } |
385+
tag!("n") => { |_| "\n" } |
386+
tag!("r") => { |_| "\r" } |
387+
tag!("f") => { |_| "\x0C" } |
388+
tag!("'") => { |_| "'" } |
389+
tag!("\"") => { |_| "\"" } |
390+
tag!("\\") => { |_| "\\" }
391+
)));
392+
382393
named!(
383394
string_parser<&str, String>,
384395
map!(
385-
terminated!(take_until!("\""), tag("\"")),
396+
terminated!(escaped_string_parser, tag("\"")),
386397
|v| String::from(v)
387398
)
388399
);

0 commit comments

Comments
 (0)