diff options
author | Andreas Lind Petersen <andreas@one.com> | 2013-03-31 11:07:31 +0200 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2013-03-31 13:36:22 +0300 |
commit | 81f5efe39a6d44d3037dda8bcff01195f5699139 (patch) | |
tree | c8afa20fce769b2ee5146bc75950467cf35dc160 | |
parent | 69dde0462b409a709c4a8cddffc1bb8d641201e2 (diff) | |
download | tracifyjs-81f5efe39a6d44d3037dda8bcff01195f5699139.tar.gz tracifyjs-81f5efe39a6d44d3037dda8bcff01195f5699139.zip |
Output, to_ascii: Escape non-ascii chars with \xnn instead of \unnnn whenever possible.
-rw-r--r-- | lib/output.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/output.js b/lib/output.js index 42b3aad9..b99bfa63 100644 --- a/lib/output.js +++ b/lib/output.js @@ -72,8 +72,13 @@ function OutputStream(options) { function to_ascii(str) { return str.replace(/[\u0080-\uffff]/g, function(ch) { var code = ch.charCodeAt(0).toString(16); - while (code.length < 4) code = "0" + code; - return "\\u" + code; + if (code.length <= 2) { + while (code.length < 2) code = "0" + code; + return "\\x" + code; + } else { + while (code.length < 4) code = "0" + code; + return "\\u" + code; + } }); }; |