8000 Reuse original order · symfony/symfony@d0c5f9c · GitHub
[go: up one dir, main page]

Skip to content

Commit d0c5f9c

Browse files
committed
Reuse original order
1 parent 143a05d commit d0c5f9c

File tree

1 file changed

+13
-13
lines changed
  • src/Symfony/Component/Intl/Resources/emoji
< 10000 div class="Box-sc-g0xbh4-0 prc-PageLayout-ContentWrapper-b-QRo Commit-module__SplitPageLayout_Content--ZY6yu" data-is-hidden="false">

1 file changed

+13
-13
lines changed

src/Symfony/Component/Intl/Resources/emoji/build.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,10 @@ public static function buildRules(array $emojisCodePoints): Generator
6868
$ignored = [];
6969
$mapsByLocale = [];
7070

71-
// Build a map of all emojis, ordered by code points length
72-
$orderedEmojis = [...$emojisCodePoints];
73-
uksort($orderedEmojis, fn ($a, $b) => mb_strlen($b, 'utf-8') <=> mb_strlen($a, 'utf-8'));
74-
$emojiMap = array_fill_keys($orderedEmojis, null);
75-
7671
foreach ($files as $file) {
7772
$locale = $file->getBasename('.xml');
7873

79-
$mapsByLocale[$locale] ??= [...$emojiMap];
74+
$mapsByLocale[$locale] ??= [];
8075

8176
$document = new DOMDocument();
8277
$document->loadXML(file_get_contents($file));
@@ -104,24 +99,29 @@ public static function buildRules(array $emojisCodePoints): Generator
10499
if (!self::testEmoji($emoji, $locale, $emojiCodePoints)) {
105100
continue;
106101
}
107-
$mapsByLocale[$locale][$emoji] = $name;
102+
$codePointsCount = mb_strlen($emoji);
103+
$mapsByLocale[$locale][$codePointsCount][$emoji] = $name;
108104
}
109105
}
110106

111107
ksort($mapsByLocale);
112108

113-
foreach ($mapsByLocale as $locale => $localeMap) {
109+
foreach ($mapsByLocale as $locale => $localeMaps) {
114110
$parentLocale = $locale;
115111

116112
while (false !== $i = strrpos($parentLocale, '_')) {
117113
$parentLocale = substr($parentLocale, 0, $i);
118-
// Override parent map with child one, ensuring the result map contains
119-
// all the emojis while keeping a shared order between locales
120-
$localeMap = [...($mapsByLocale[$parentLocale] ?? []), ...array_filter($localeMap)];
114+
$parentMaps = $mapsByLocale[$parentLocale] ?? [];
115+
foreach ($parentMaps as $codePointsCount => $parentMap) {
116+
// Ensuring the result map contains all the emojis from the parent map
117+
// if not already defined by the current locale
118+
$localeMaps[$codePointsCount] = [...$parentMap, ...$localeMaps[$codePointsCount] ?? []];
119+
}
121120
}
122121

123-
if ($localeMap = [...array_filter($localeMap)]) {
124-
yield strtolower("emoji-$locale") => $localeMap;
122+
// Skip locales without any emoji
123+
if ($localeRules = self::createRules($localeMaps)) {
124+
yield strtolower("emoji-$locale") => $localeRules;
125125
}
126126
}
127127
}

0 commit comments

Comments
 (0)
0