Skip to content

Commit 893b11e

Browse files
authored
Merge pull request #45 from arnog/patch-1
Fix calculation of Unicode surrogate pairs
2 parents b3e508f + 2a7f1e9 commit 893b11e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

parse-css.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function preprocess(str) {
4747
// Decode a surrogate pair into an astral codepoint.
4848
var lead = code - 0xd800;
4949
var trail = str.charCodeAt(i+1) - 0xdc00;
50-
code = Math.pow(2, 20) + lead * Math.pow(2, 10) + trail;
50+
code = Math.pow(2, 16) + lead * Math.pow(2, 10) + trail;
5151
i++;
5252
}
5353
codepoints.push(code);
@@ -58,7 +58,7 @@ function preprocess(str) {
5858
function stringFromCode(code) {
5959
if(code <= 0xffff) return String.fromCharCode(code);
6060
// Otherwise, encode astral char as surrogate pair.
61-
code -= Math.pow(2, 20);
61+
code -= Math.pow(2, 16);
6262
var lead = Math.floor(code/Math.pow(2, 10)) + 0xd800;
6363
var trail = code % Math.pow(2, 10) + 0xdc00;
6464
return String.fromCharCode(lead) + String.fromCharCode(trail);

0 commit comments

Comments
 (0)