1
0
mirror of https://github.com/twitter/twemoji.git synced 2024-07-03 03:18:58 +00:00

Fix sorting, and grabTheRightIcon to not encode 200d in a string

This commit is contained in:
Tom Wuttke 2016-03-01 18:53:15 -08:00
parent 13822121df
commit c80250121b
5 changed files with 29 additions and 27 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
2/twemoji.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -344,9 +344,14 @@ Queue([
var result = [];
var charClass = [];
var charRange = [];
items.sort(sortMethod).forEach(function(item) {
var itemParts = item.split('\\u');
items.map(function (item) {
// Convert from "\u2963\ufe0f" into ["2963", "fe0f"]
return item.split('\\u').slice(1);
}).sort(sortMethod).forEach(function (itemParts) {
var prefix = itemParts.slice(0, -1).join('\\u');
if (prefix) {
prefix = '\\u' + prefix;
}
var suffix = itemParts.slice(-1);
if (prefix !== currentPrefix) {
flushCharClass();
@ -363,7 +368,8 @@ Queue([
flushCharClass();
return result.join('|');
function sortMethod(a,b) {
// a and b are arrays of hex UCS-2 units
function sortMethod(a, b) {
return !a.length ? 0 :
b.length - a.length ||
parseInt(b[0], 16) - parseInt(a[0], 16) ||
@ -716,15 +722,14 @@ function createTwemoji(re) {
/**
* Used to both remove the possible variant
* and to convert utf16 into code points.
* If there is a zero-width-joiner, leave the variant in.
* If there is a zero-width-joiner (U+200D), leave the variants in.
* @param string the raw text of the emoji match
*/
function grabTheRightIcon(rawText) {
// if variant is present as \uFE0F
return toCodePoint(
rawText.indexOf('\u200D') < 0 ?
rawText.replace(/\uFE0F/g, '') :
rawText
return toCodePoint(/\u200D/.test(rawText) ?
rawText :
rawText.replace(/\uFE0F/g, '')
);
}