PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.87
WindPress – Tailwind CSS integration for WordPress v3.2.87
3.2.90 3.2.89 3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 All 144 releases
windpress / vendor / symfony / polyfill-intl-normalizer / Normalizer.php

Normalizer.php in WindPress – Tailwind CSS integration for WordPress 3.2.87, at vendor/symfony/polyfill-intl-normalizer/Normalizer.php

261 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace Symfony\Polyfill\Intl\Normalizer;
12
13 /**
14 * Normalizer is a PHP fallback implementation of the Normalizer class provided by the intl extension.
15 *
16 * It has been validated with Unicode 6.3 Normalization Conformance Test.
17 * See http://www.unicode.org/reports/tr15/ for detailed info about Unicode normalizations.
18 *
19 * @author Nicolas Grekas <p@tchwork.com>
20 *
21 * @internal
22 */
23 class Normalizer
24 {
25 public const FORM_D = \Normalizer::FORM_D;
26 public const FORM_KD = \Normalizer::FORM_KD;
27 public const FORM_C = \Normalizer::FORM_C;
28 public const FORM_KC = \Normalizer::FORM_KC;
29 public const NFD = \Normalizer::NFD;
30 public const NFKD = \Normalizer::NFKD;
31 public const NFC = \Normalizer::NFC;
32 public const NFKC = \Normalizer::NFKC;
33 private static $C;
34 private static $D;
35 private static $KD;
36 private static $cC;
37 private static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4];
38 private static $ASCII = " eiasntrolud][cmp'\ng|hv.fb,:=-q10C2*yx)(L9AS/P\"EjMIk3>5T<D4}B{8FwR67UGN;JzV#HOW_&!K?XQ%Y\\\tZ+~^\$@`\x00\x01\x02\x03\x04\x05\x06\x07\x08\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
39 public static function isNormalized(string $s, int $form = self::FORM_C)
40 {
41 if (!\in_array($form, [self::NFD, self::NFKD, self::NFC, self::NFKC])) {
42 return \false;
43 }
44 if (!isset($s[strspn($s, self::$ASCII)])) {
45 return \true;
46 }
47 if (self::NFC == $form && preg_match('//u', $s) && !preg_match('/[^\x00-\x{2FF}]/u', $s)) {
48 return \true;
49 }
50 return self::normalize($s, $form) === $s;
51 }
52 public static function normalize(string $s, int $form = self::FORM_C)
53 {
54 if (!preg_match('//u', $s)) {
55 return \false;
56 }
57 switch ($form) {
58 case self::NFC:
59 $C = \true;
60 $K = \false;
61 break;
62 case self::NFD:
63 $C = \false;
64 $K = \false;
65 break;
66 case self::NFKC:
67 $C = \true;
68 $K = \true;
69 break;
70 case self::NFKD:
71 $C = \false;
72 $K = \true;
73 break;
74 default:
75 if (\defined('WindPressDeps\Normalizer::NONE') && \Normalizer::NONE == $form) {
76 return $s;
77 }
78 if (80000 > \PHP_VERSION_ID) {
79 return \false;
80 }
81 throw new \ValueError('normalizer_normalize(): Argument #2 ($form) must be a a valid normalization form');
82 }
83 if ('' === $s) {
84 return '';
85 }
86 if ($K && null === self::$KD) {
87 self::$KD = self::getData('compatibilityDecomposition');
88 }
89 if (null === self::$D) {
90 self::$D = self::getData('canonicalDecomposition');
91 self::$cC = self::getData('combiningClass');
92 }
93 if (null !== $mbEncoding = 2 & (int) \ini_get('mbstring.func_overload') ? mb_internal_encoding() : null) {
94 mb_internal_encoding('8bit');
95 }
96 $r = self::decompose($s, $K);
97 if ($C) {
98 if (null === self::$C) {
99 self::$C = self::getData('canonicalComposition');
100 }
101 $r = self::recompose($r);
102 }
103 if (null !== $mbEncoding) {
104 mb_internal_encoding($mbEncoding);
105 }
106 return $r;
107 }
108 private static function recompose($s)
109 {
110 $ASCII = self::$ASCII;
111 $compMap = self::$C;
112 $combClass = self::$cC;
113 $ulenMask = self::$ulenMask;
114 $result = $tail = '';
115 $i = $s[0] < "\x80" ? 1 : $ulenMask[$s[0] & "\xf0"];
116 $len = \strlen($s);
117 $lastUchr = substr($s, 0, $i);
118 $lastUcls = isset($combClass[$lastUchr]) ? 256 : 0;
119 while ($i < $len) {
120 if ($s[$i] < "\x80") {
121 // ASCII chars
122 if ($tail) {
123 $lastUchr .= $tail;
124 $tail = '';
125 }
126 if ($j = strspn($s, $ASCII, $i + 1)) {
127 $lastUchr .= substr($s, $i, $j);
128 $i += $j;
129 }
130 $result .= $lastUchr;
131 $lastUchr = $s[$i];
132 $lastUcls = 0;
133 ++$i;
134 continue;
135 }
136 $ulen = $ulenMask[$s[$i] & "\xf0"];
137 $uchr = substr($s, $i, $ulen);
138 if ($lastUchr < "ᄀ" || "ᄒ" < $lastUchr || $uchr < "�
139 �" || "�
140 �" < $uchr || $lastUcls) {
141 // Table lookup and combining chars composition
142 $ucls = $combClass[$uchr] ?? 0;
143 if (isset($compMap[$lastUchr . $uchr]) && (!$lastUcls || $lastUcls < $ucls)) {
144 $lastUchr = $compMap[$lastUchr . $uchr];
145 } elseif ($lastUcls = $ucls) {
146 $tail .= $uchr;
147 } else {
148 if ($tail) {
149 $lastUchr .= $tail;
150 $tail = '';
151 }
152 $result .= $lastUchr;
153 $lastUchr = $uchr;
154 }
155 } else {
156 // Hangul chars
157 $L = \ord($lastUchr[2]) - 0x80;
158 $V = \ord($uchr[2]) - 0xa1;
159 $T = 0;
160 $uchr = substr($s, $i + $ulen, 3);
161 if ("" <= $uchr && $uchr <= "") {
162 $T = \ord($uchr[2]) - 0xa7;
163 0 > $T && $T += 0x40;
164 $ulen += 3;
165 }
166 $L = 0xac00 + ($L * 21 + $V) * 28 + $T;
167 $lastUchr = \chr(0xe0 | $L >> 12) . \chr(0x80 | $L >> 6 & 0x3f) . \chr(0x80 | $L & 0x3f);
168 }
169 $i += $ulen;
170 }
171 return $result . $lastUchr . $tail;
172 }
173 private static function decompose($s, $c)
174 {
175 $result = '';
176 $ASCII = self::$ASCII;
177 $decompMap = self::$D;
178 $combClass = self::$cC;
179 $ulenMask = self::$ulenMask;
180 if ($c) {
181 $compatMap = self::$KD;
182 }
183 $c = [];
184 $i = 0;
185 $len = \strlen($s);
186 while ($i < $len) {
187 if ($s[$i] < "\x80") {
188 // ASCII chars
189 if ($c) {
190 ksort($c);
191 $result .= implode('', $c);
192 $c = [];
193 }
194 $j = 1 + strspn($s, $ASCII, $i + 1);
195 $result .= substr($s, $i, $j);
196 $i += $j;
197 continue;
198 }
199 $ulen = $ulenMask[$s[$i] & "\xf0"];
200 $uchr = substr($s, $i, $ulen);
201 $i += $ulen;
202 if ($uchr < "" || "" < $uchr) {
203 // Table lookup
204 if ($uchr !== $j = $compatMap[$uchr] ?? $decompMap[$uchr] ?? $uchr) {
205 $uchr = $j;
206 $j = \strlen($uchr);
207 $ulen = $uchr[0] < "\x80" ? 1 : $ulenMask[$uchr[0] & "\xf0"];
208 if ($ulen != $j) {
209 // Put trailing chars in $s
210 $j -= $ulen;
211 $i -= $j;
212 if (0 > $i) {
213 $s = str_repeat(' ', -$i) . $s;
214 $len -= $i;
215 $i = 0;
216 }
217 while ($j--) {
218 $s[$i + $j] = $uchr[$ulen + $j];
219 }
220 $uchr = substr($uchr, 0, $ulen);
221 }
222 }
223 if (isset($combClass[$uchr])) {
224 // Combining chars, for sorting
225 if (!isset($c[$combClass[$uchr]])) {
226 $c[$combClass[$uchr]] = '';
227 }
228 $c[$combClass[$uchr]] .= $uchr;
229 continue;
230 }
231 } else {
232 // Hangul chars
233 $uchr = unpack('C*', $uchr);
234 $j = ($uchr[1] - 224 << 12) + ($uchr[2] - 128 << 6) + $uchr[3] - 0xac80;
235 $uchr = "\xe1\x84" . \chr(0x80 + (int) ($j / 588)) . "\xe1\x85" . \chr(0xa1 + (int) ($j % 588 / 28));
236 if ($j %= 28) {
237 $uchr .= $j < 25 ? "\xe1\x86" . \chr(0xa7 + $j) : "\xe1\x87" . \chr(0x67 + $j);
238 }
239 }
240 if ($c) {
241 ksort($c);
242 $result .= implode('', $c);
243 $c = [];
244 }
245 $result .= $uchr;
246 }
247 if ($c) {
248 ksort($c);
249 $result .= implode('', $c);
250 }
251 return $result;
252 }
253 private static function getData($file)
254 {
255 if (file_exists($file = __DIR__ . '/Resources/unidata/' . $file . '.php')) {
256 return require $file;
257 }
258 return \false;
259 }
260 }
261