Skip to content

Commit

Permalink
Rename codePoints into codeUnits as that’s more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasbynens committed Sep 20, 2013
1 parent 600e00d commit 7d205c2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fromcodepoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (!String.fromCodePoint) {
String.fromCodePoint = function() {
var codePoints = [];
var codeUnits = [];
var floor = Math.floor;
var highSurrogate;
var lowSurrogate;
Expand All @@ -20,15 +20,15 @@ if (!String.fromCodePoint) {
throw RangeError('Invalid code point: ' + codePoint);
}
if (codePoint <= 0xFFFF) { // BMP code point
codePoints.push(codePoint);
codeUnits.push(codePoint);
} else { // Astral code point; split in surrogate halves
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
codePoint -= 0x10000;
highSurrogate = (codePoint >> 10) + 0xD800;
lowSurrogate = (codePoint % 0x400) + 0xDC00;
codePoints.push(highSurrogate, lowSurrogate);
codeUnits.push(highSurrogate, lowSurrogate);
}
}
return String.fromCharCode.apply(null, codePoints);
return String.fromCharCode.apply(null, codeUnits);
};
}

0 comments on commit 7d205c2

Please # to comment.