Skip to content

Commit

Permalink
Merge pull request #81 from matecat/emoji-fix
Browse files Browse the repository at this point in the history
Emoji fix
  • Loading branch information
mauretto78 authored Dec 28, 2023
2 parents b6db2ca + b0e3a24 commit d3ebb63
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Utils/Emoji.php
Original file line number Diff line number Diff line change
Expand Up @@ -6897,7 +6897,7 @@ class Emoji {
'🏼' => '🏼',
'🏽' => '🏽',
'🏾' => '🏾',
'🟿' => '🏿',
'🏿' => '🏿',
'' => '️',
'' => '⃣',
'𝐀' => '𝐀',
Expand Down Expand Up @@ -7401,7 +7401,7 @@ class Emoji {
'􏰀' => '􏰀',
'🛼' => '🛼',
'🥷' => '🥷',
'🤌' => '🏼',
'🤌' => '🤌',
"󠅸" => '󠅸', // invisible glyph
'󠄀' => '󠄀',
'󠇡' => '󠇡',
Expand Down Expand Up @@ -7463,6 +7463,10 @@ public static function toEntity( $str ) {
return $str;
}

/**
* @param $str
* @return string
*/
public static function toEmoji( $str ) {
self::generateReverseMap();
preg_match_all( '/&#[0-9a-fA-F]+;/', $str, $emoji_entity_list, PREG_PATTERN_ORDER );
Expand Down
24 changes: 24 additions & 0 deletions tests/EmojiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,28 @@ public function entityToEmojiTest() {
$this->assertEquals( 'Questo ✕ è un emoji a croce 􀅖🪙 manina 👋🏻', Emoji::toEmoji( $segment ) );
}

/**
* This test is performed on the same emoji (flexed arm) in different shades
*
* @test
*/
public function canEncodeAndDecodeDifferentShades()
{
$emojis = [
'🤌',
'💪🏻',
'💪🏽',
'💪🏾',
'💪🏿',
'💪🏿'
];

foreach ($emojis as $i => $emoji){

$entity = Emoji::toEntity($emoji);
$toEmoji = Emoji::toEmoji($entity);

$this->assertEquals($emojis[$i], $toEmoji);
}
}
}

0 comments on commit d3ebb63

Please sign in to comment.