@@ -21,8 +21,9 @@ Elm.Native.Show.make = function(elm) {
21 return v ? "True" : "False";
21 return v ? "True" : "False";
22 } else if (type === "number") {
22 } else if (type === "number") {
23 return v+"";
23 return v+"";
24− } else if (type === "string" && v.length < 2) {
24+ } else if (type === "string") {
25− return "'" + showChar(v) + "'";
25+ var quote = v.length === 1 ? "'" : '"';
26+ return quote + addSlashes(v) + quote;
26 } else if (type === "object" && '_' in v) {
27 } else if (type === "object" && '_' in v) {
27 var output = [];
28 var output = [];
28 for (var k in v._) {
29 for (var k in v._) {
@@ -45,18 +46,13 @@ Elm.Native.Show.make = function(elm) {
46 return "(" + output.join(",") + ")";
47 return "(" + output.join(",") + ")";
47 } else if (v.ctor === "::") {
48 } else if (v.ctor === "::") {
48− var isStr = typeof v._0 === "string",
49− start = isStr ? '"' : "[",
50− end = isStr ? '"' : "]",
51− sep = isStr ? "" : ",",
52− f = !isStr ? toString : showChar;
53− var output = start + f(v._0);
49+ var output = '[' + toString(v._0);
55 while (v.ctor === "::") {
51 while (v.ctor === "::") {
56− output += sep + f(v._0);
52+ output += "," + toString(v._0);
59− return output + end;
55+ return output + ']';
60 } else if (v.ctor === "[]") {
56 } else if (v.ctor === "[]") {
61 return "[]";
57 return "[]";
62 } else if (v.ctor === "RBNode" || v.ctor === "RBEmpty") {
58 } else if (v.ctor === "RBNode" || v.ctor === "RBEmpty") {
@@ -83,16 +79,15 @@ Elm.Native.Show.make = function(elm) {
83 return "<internal structure>";
79 return "<internal structure>";
86− function showChar (c) {
82+ function addSlashes(str) {
87− return c === '\n' ? '\\n' :
83+ return str.replace(/\n/g, '\\n')
88− c === '\t' ? '\\t' :
84+ .replace(/\t/g, '\\t')
89− c === '\b' ? '\\b' :
85+ .replace(/\r/g, '\\r')
90− c === '\r' ? '\\r' :
86+ .replace(/\v/g, '\\v')
91− c === '\v' ? '\\v' :
87+ .replace(/\0/g, '\\0')
92− c === '\0' ? '\\0' :
88+ .replace(/\'/g, "\\'")
93− c === '\'' ? "\\'" :
89+ .replace(/\"/g, '\\"')
94− c === '\"' ? '\\"' :
90+ .replace(/\\/g, '\\\\')
95− c === '\\' ? '\\\\' : c;
98 return elm.Native.Show.values = { show:toString };
93 return elm.Native.Show.values = { show:toString };