Output, to_ascii: Escape non-ascii chars with \xnn instead of \unnnn whenever possible.

This commit is contained in:
Andreas Lind Petersen
2013-03-31 11:07:31 +02:00
committed by Mihai Bazon
parent 69dde0462b
commit 81f5efe39a

View 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;
}
});
};