Output, to_ascii: Escape non-ascii chars with \xnn instead of \unnnn whenever possible.
authorAndreas Lind Petersen <andreas@one.com>
Sun, 31 Mar 2013 09:07:31 +0000 (11:07 +0200)
committerMihai Bazon <mihai@bazon.net>
Sun, 31 Mar 2013 10:36:22 +0000 (13:36 +0300)
lib/output.js

index 42b3aad..b99bfa6 100644 (file)
@@ -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;
+            }
         });
     };