Этот коммит содержится в:
Harrison Healey
2016-03-23 18:10:25 -04:00
родитель 5689bb7398
Коммит 5cfae469a5

Просмотреть файл

@@ -32,27 +32,28 @@ const emoticonPatterns = {
export const emoticons = initializeEmoticons(); export const emoticons = initializeEmoticons();
function initializeEmoticons() { function initializeEmoticons() {
const emoticons = new Map(); const emoticonMap = new Map();
for (const emoji of emojis) { for (const emoji of emojis) {
const unicode = emoji.emoji; const unicode = emoji.emoji;
let filename = ''; let filename = '';
if (emoji.emoji) { if (unicode) {
// this is a unicode emoji so the character code determines the file name // this is a unicode emoji so the character code determines the file name
const code = fixedCharCodeAt(emoji.emoji, 0).toString(16); for (let i = 0; i < unicode.length; i += 2) {
filename = pad(code.toString(16)); const code = fixedCharCodeAt(unicode, i);
if (emoji.emoji.length > 2) { // ignore variation selector characters
// some emojis like the country flags span multiple utf-16 characters if (code >= 0xfe00 && code <= 0xfe0f) {
for (let i = 2; i < emoji.emoji.length; i += 2) { continue;
const code = fixedCharCodeAt(emoji.emoji, i);
// ignore variation selectors
if (code < 0xfe00 || code > 0xfe0f) {
filename += '-' + pad(code.toString(16));
}
} }
// some emoji (such as country flags) span multiple unicode characters
if (i !== 0) {
filename += '-';
}
filename += pad(code.toString(16));
} }
} else { } else {
// this isn't a unicode emoji so the first alias determines the file name // this isn't a unicode emoji so the first alias determines the file name
@@ -60,14 +61,14 @@ function initializeEmoticons() {
} }
for (const alias of emoji.aliases) { for (const alias of emoji.aliases) {
emoticons.set(alias, { emoticonMap.set(alias, {
alias, alias,
path: getImagePathForEmoticon(filename) path: getImagePathForEmoticon(filename)
}); });
} }
} }
return emoticons; return emoticonMap;
} }
// Pads a hexadecimal number with zeroes to be at least 4 digits long // Pads a hexadecimal number with zeroes to be at least 4 digits long
@@ -89,18 +90,18 @@ function fixedCharCodeAt(str, idx = 0) {
// High surrogate (could change last hex to 0xDB7F to treat high // High surrogate (could change last hex to 0xDB7F to treat high
// private surrogates as single characters) // private surrogates as single characters)
if (0xD800 <= code && code <= 0xDBFF) { if (code >= 0xD800 && code <= 0xDBFF) {
const hi = code; const hi = code;
const low = str.charCodeAt(idx + 1); const low = str.charCodeAt(idx + 1);
if (isNaN(low)) { if (isNaN(low)) {
console.log('High surrogate not followed by low surrogate in fixedCharCodeAt()'); // eslint-ignore-line console.log('High surrogate not followed by low surrogate in fixedCharCodeAt()'); // eslint-disable-line
} }
return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000; return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
} }
if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate if (code >= 0xDC00 && code <= 0xDFFF) { // Low surrogate
// We return false to allow loops to skip this iteration since should have // We return false to allow loops to skip this iteration since should have
// already handled high surrogate above in the previous iteration // already handled high surrogate above in the previous iteration
return false; return false;