Output, to_ascii: Escape non-ascii chars with \xnn instead of \unnnn whenever possible.
This commit is contained in:
committed by
Mihai Bazon
parent
69dde0462b
commit
81f5efe39a
@@ -72,8 +72,13 @@ function OutputStream(options) {
|
|||||||
function to_ascii(str) {
|
function to_ascii(str) {
|
||||||
return str.replace(/[\u0080-\uffff]/g, function(ch) {
|
return str.replace(/[\u0080-\uffff]/g, function(ch) {
|
||||||
var code = ch.charCodeAt(0).toString(16);
|
var code = ch.charCodeAt(0).toString(16);
|
||||||
|
if (code.length <= 2) {
|
||||||
|
while (code.length < 2) code = "0" + code;
|
||||||
|
return "\\x" + code;
|
||||||
|
} else {
|
||||||
while (code.length < 4) code = "0" + code;
|
while (code.length < 4) code = "0" + code;
|
||||||
return "\\u" + code;
|
return "\\u" + code;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user