Skip to content

Commit 43b6eb3

Browse files
committed
Merge pull request #54 from michaelficarra/GH-51
fixes #51: properly escape output of Show instance for Char
2 parents eb48931 + 8b5dd43 commit 43b6eb3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Prelude.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,20 @@ exports.showNumberImpl = function (n) {
210210
};
211211

212212
exports.showCharImpl = function (c) {
213-
return c === "'" ? "'\\''" : "'" + c + "'";
213+
var code = c.charCodeAt(0);
214+
if (code < 0x20 || code === 0x7F) {
215+
switch (c) {
216+
case "\a": return "'\\a'";
217+
case "\b": return "'\\b'";
218+
case "\f": return "'\\f'";
219+
case "\n": return "'\\n'";
220+
case "\r": return "'\\r'";
221+
case "\t": return "'\\t'";
222+
case "\v": return "'\\v'";
223+
}
224+
return "'\\" + code.toString(10) + "'";
225+
}
226+
return c === "'" || c === "\\" ? "'\\" + c + "'" : "'" + c + "'";
214227
};
215228

216229
exports.showStringImpl = function (s) {

0 commit comments

Comments
 (0)