1
0
mirror of https://github.com/twitter/twemoji.git synced 2024-10-02 21:02:03 +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 result = [];
var charClass = []; var charClass = [];
var charRange = []; var charRange = [];
items.sort(sortMethod).forEach(function(item) { items.map(function (item) {
var itemParts = item.split('\\u'); // 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'); var prefix = itemParts.slice(0, -1).join('\\u');
if (prefix) {
prefix = '\\u' + prefix;
}
var suffix = itemParts.slice(-1); var suffix = itemParts.slice(-1);
if (prefix !== currentPrefix) { if (prefix !== currentPrefix) {
flushCharClass(); flushCharClass();
@ -363,7 +368,8 @@ Queue([
flushCharClass(); flushCharClass();
return result.join('|'); 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 : return !a.length ? 0 :
b.length - a.length || b.length - a.length ||
parseInt(b[0], 16) - parseInt(a[0], 16) || parseInt(b[0], 16) - parseInt(a[0], 16) ||
@ -716,15 +722,14 @@ function createTwemoji(re) {
/** /**
* Used to both remove the possible variant * Used to both remove the possible variant
* and to convert utf16 into code points. * 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 * @param string the raw text of the emoji match
*/ */
function grabTheRightIcon(rawText) { function grabTheRightIcon(rawText) {
// if variant is present as \uFE0F // if variant is present as \uFE0F
return toCodePoint( return toCodePoint(/\u200D/.test(rawText) ?
rawText.indexOf('\u200D') < 0 ? rawText :
rawText.replace(/\uFE0F/g, '') : rawText.replace(/\uFE0F/g, '')
rawText
); );
} }