Skip to content

Commit eaf829c

Browse files
authored
Merge pull request #9 from tobyzerner/RegexpBuilder
Normalize codepoints for Twemoji
2 parents a042ff6 + 4966856 commit eaf829c

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

generate.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88

99
include __DIR__.'/vendor/autoload.php';
1010

11-
$emoji = Spatie\Emoji\Emoji::all();
11+
// Normalize codepoints for Twemoji
12+
$emoji = array_map(function ($emoji) {
13+
if (strpos($emoji, "\u{200D}") === false) {
14+
$emoji = str_replace("\u{FE0F}", '', $emoji);
15+
}
16+
17+
return $emoji;
18+
}, Spatie\Emoji\Emoji::all());
1219

1320
// Work on bytes, output a PCRE regexp made of ASCII characters
1421
$builder = new s9e\RegexpBuilder\Builder([

src/Twemoji.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Twemoji implements JsonSerializable
1616
protected array $codepoints;
1717

1818
/**
19-
* @param string[] $codepoints
19+
* @param string[] $codepoints
2020
*/
2121
public function __construct(array $codepoints)
2222
{
@@ -32,9 +32,14 @@ public static function emoji(string $emoji): self
3232
$chars
3333
);
3434

35-
$normalized = array_diff($codepoints, ['fe0f']);
35+
// Normalize codepoints for Twemoji
36+
$codepoints[0] = ltrim($codepoints[0], '0');
3637

37-
return new static($normalized);
38+
if (! in_array('200d', $codepoints)) {
39+
$codepoints = array_diff($codepoints, ['fe0f']);
40+
}
41+
42+
return new static($codepoints);
3843
}
3944

4045
public static function text(string $text): EmojiText

0 commit comments

Comments
 (0)