aboutsummaryrefslogtreecommitdiff
path: root/lib/output.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-12-28 18:06:51 +0000
committerGitHub <noreply@github.com>2019-12-28 18:06:51 +0000
commit22b47cdd639263313317b77a3166afad767a7ef6 (patch)
tree9229cce61dbab21907e03434b9e799f4994898e7 /lib/output.js
parent4cf612dc9fb0d96b48e8e156810c00c06a6a2a46 (diff)
downloadtracifyjs-22b47cdd639263313317b77a3166afad767a7ef6.tar.gz
tracifyjs-22b47cdd639263313317b77a3166afad767a7ef6.zip
improve unicode handling (#3648)
Diffstat (limited to 'lib/output.js')
-rw-r--r--lib/output.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/output.js b/lib/output.js
index cc39c2df..38b4f8bc 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -119,15 +119,20 @@ function OutputStream(options) {
});
} : function(str) {
var s = "";
- for (var i = 0; i < str.length; i++) {
- if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
- || is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
- s += "\\u" + str.charCodeAt(i).toString(16);
- } else {
- s += str[i];
+ for (var i = 0, j = 0; i < str.length; i++) {
+ var code = str.charCodeAt(i);
+ if (is_surrogate_pair_head(code)) {
+ if (is_surrogate_pair_tail(str.charCodeAt(i + 1))) {
+ i++;
+ continue;
+ }
+ } else if (!is_surrogate_pair_tail(code)) {
+ continue;
}
+ s += str.slice(j, i) + "\\u" + code.toString(16);
+ j = i + 1;
}
- return s;
+ return j == 0 ? str : s + str.slice(j);
};
function make_string(str, quote) {