Permalink
Browse files

Output, to_ascii: Escape non-ascii chars with \xnn instead of \unnnn …

…whenever possible.
  • Loading branch information...
1 parent 69dde04 commit 81f5efe39a6d44d3037dda8bcff01195f5699139 @papandreou papandreou committed with Mar 31, 2013
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/output.js
View
9 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;
+ }
});
};

0 comments on commit 81f5efe

Please sign in to comment.