extend support for Unicode (#4228)

This commit is contained in:
Alex Lam S.L
2020-10-19 02:34:17 +01:00
committed by GitHub
parent 96bf7fceab
commit 8ecaa40c6e
5 changed files with 175 additions and 148 deletions

View File

@@ -107,6 +107,9 @@ function OutputStream(options) {
var OUTPUT = "";
var to_utf8 = options.ascii_only ? function(str, identifier) {
if (identifier) str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) {
return "\\u{" + (ch.charCodeAt(0) - 0xd7c0 << 10 | ch.charCodeAt(1) - 0xdc00).toString(16) + "}";
});
return str.replace(/[\u0000-\u001f\u007f-\uffff]/g, function(ch) {
var code = ch.charCodeAt(0).toString(16);
if (code.length <= 2 && !identifier) {