Skip to content

Commit

Permalink
一部絵文字のバイト変換がおかしくなる問題の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
slofp committed Sep 16, 2023
1 parent f6e2cb8 commit a32f8b3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/frontend/src/scripts/emojiKitchen/emojiMixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,24 @@ const convertBase = (value, from_base, to_base) => {
return new_value || '0';
};

const emojiSplit = String.fromCodePoint(0x200d);
const hexEncodeEmoji = (chr) => {
if (chr.length !== 1) {
if (chr.length === 3) return hexEncodeEmoji(chr.slice(0, 2)) + '-' + hexEncodeEmoji(chr.slice(2, chr.length));
else if (chr.length === 2) {
const hi = chr.charCodeAt(0);
const lo = chr.charCodeAt(1);
if (0xD800 <= hi && hi < 0xDC00 && 0xDC00 <= lo && lo < 0xE000) {
return (0x10000 + (hi - 0xD800) * 0x400 + (lo - 0xDC00)).toString(16);
}
return ("000" + hi.toString(16)).slice(-4) + '-' + ("000" + lo.toString(16)).slice(-4);
return hi.toString(16) + '-' + lo.toString(16);
}
else if (chr.length === 1) {
return chr.charCodeAt(0).toString(16);
}
else {
return ("000" + chr.charCodeAt(0).toString(16)).slice(-4);
const sp = chr.split(emojiSplit);
if (sp.length !== 2) return '';
return hexEncodeEmoji(sp[0]) + '-200d-' + hexEncodeEmoji(sp[1]);
}
};

Expand Down

0 comments on commit a32f8b3

Please sign in to comment.