From 4a45ed7e1f80a7d3e4032e08eb499dab3412453f Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Sat, 23 Mar 2019 01:09:05 +0100 Subject: Parse unicode escapes in string --- dhall_core/src/printer.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'dhall_core/src/printer.rs') diff --git a/dhall_core/src/printer.rs b/dhall_core/src/printer.rs index 508c1c8..5ecf5ce 100644 --- a/dhall_core/src/printer.rs +++ b/dhall_core/src/printer.rs @@ -206,13 +206,19 @@ impl Expr { for x in a.iter() { match x { InterpolatedTextContents::Text(a) => { - // TODO Format all escapes properly - f.write_str( - &a.replace("\n", "\\n") - .replace("\t", "\\t") - .replace("\r", "\\r") - .replace("\"", "\\\""), - )?; + for c in a.chars() { + match c { + '\\' => f.write_str("\\\\"), + '"' => f.write_str("\\\""), + '$' => f.write_str("\\$"), + '\u{0008}' => f.write_str("\\b"), + '\u{000C}' => f.write_str("\\f"), + '\n' => f.write_str("\\n"), + '\r' => f.write_str("\\r"), + '\t' => f.write_str("\\t"), + c => write!(f, "{}", c), + }?; + } } InterpolatedTextContents::Expr(e) => { f.write_str("${ ")?; -- cgit v1.2.3