diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2018-06-17 09:12:52 -0400 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2018-06-17 09:12:52 -0400 |
commit | 095c2640aa2070ed4e2765875238d5e6e6673856 (patch) | |
tree | 9306beb3fef29a99d9436dc00e2d8c57fb3e0c7b /lib/ur/json.ur | |
parent | 8c58ba2e1db6e97ca1f18fd9ca52ffead53e4a4f (diff) | |
parent | 34eb9eba9a724433f9c37c39cf43e9e10cf55220 (diff) |
Merge branch 'upstream' into dfsg_clean20180616+dfsg
Diffstat (limited to 'lib/ur/json.ur')
-rw-r--r-- | lib/ur/json.ur | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/ur/json.ur b/lib/ur/json.ur index 9288a6dd..817ec16e 100644 --- a/lib/ur/json.ur +++ b/lib/ur/json.ur @@ -46,10 +46,16 @@ fun escape s = let val ch = String.sub s 0 in - (if ch = #"\"" || ch = #"\\" then - "\\" ^ String.str ch - else - String.str ch) ^ esc (String.suffix s 1) + (case ch of + #"\n" => "\\n" + | #"\r" => "\\r" + | #"\t" => "\\t" + | #"\"" => "\\\"" + | #"\'" => "\\\'" + | #"\\" => "\\\\" + | #"/" => "\\/" + | x => String.str ch + ) ^ esc (String.suffix s 1) end in "\"" ^ esc s @@ -90,7 +96,17 @@ fun unescape s = if i+1 >= len then error <xml>JSON unescape: Bad escape sequence: {[s]}</xml> else - String.str (String.sub s (i+1)) ^ unesc (i+2) + (case String.sub s (i+1) of + #"n" => "\n" + | #"r" => "\r" + | #"t" => "\t" + | #"\"" => "\"" + | #"\'" => "\'" + | #"\\" => "\\" + | #"/" => "/" + | x => error <xml>JSON unescape: Bad escape char: {[x]}</xml>) + ^ + unesc (i+2) | _ => String.str ch ^ unesc (i+1) end in |