summaryrefslogtreecommitdiff
path: root/dhall_core/src/printer.rs
diff options
context:
space:
mode:
authorNadrieril2019-03-23 01:09:05 +0100
committerNadrieril2019-03-23 01:09:05 +0100
commit4a45ed7e1f80a7d3e4032e08eb499dab3412453f (patch)
tree4635883e5e9c72555dbc709093b82abdaeaddc6d /dhall_core/src/printer.rs
parent8110651ccf498bcf3f0cd55f3b1730d9972cf254 (diff)
Parse unicode escapes in string
Diffstat (limited to '')
-rw-r--r--dhall_core/src/printer.rs20
1 files changed, 13 insertions, 7 deletions
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<S, A: Display> Expr<S, A> {
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("${ ")?;