← All changes
|
vendor/symfony/polyfill-intl-normalizer/Normalizer.php
+42
-1
3.2.85
→
3.2.90
View file →
| @@ -33,8 +33,10 @@ | ||
| 33 | 33 | private static $C; |
| 34 | 34 | private static $D; |
| 35 | 35 | private static $KD; |
| 36 | 36 | private static $cC; |
| 37 | + private static $rawD; | |
| 38 | + private static $rawKD; | |
| 37 | 39 | private static $ulenMask = ["\xc0" => 2, "\xd0" => 2, "\xe0" => 3, "\xf0" => 4]; |
| 38 | 40 | 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 | 41 | public static function isNormalized(string $s, int $form = self::FORM_C) |
| 40 | 42 | { |
| @@ -48,8 +50,46 @@ | ||
| 48 | 50 | return \true; |
| 49 | 51 | } |
| 50 | 52 | return self::normalize($s, $form) === $s; |
| 51 | 53 | } |
| 54 | + public static function getRawDecomposition(string $s, int $form = self::FORM_C) | |
| 55 | + { | |
| 56 | + if ('' === $s || !preg_match('//u', $s)) { | |
| 57 | + return null; | |
| 58 | + } | |
| 59 | + $ulen = $s[0] < "\x80" ? 1 : self::$ulenMask[$s[0] & "\xf0"] ?? 0; | |
| 60 | + if (!$ulen || \strlen($s) !== $ulen) { | |
| 61 | + return null; | |
| 62 | + } | |
| 63 | + if (self::NFC !== $form && self::NFD !== $form && self::NFKC !== $form && self::NFKD !== $form) { | |
| 64 | + return ''; | |
| 65 | + } | |
| 66 | + if ($s >= "가" && $s <= "힣") { | |
| 67 | + $u = unpack('C*', $s); | |
| 68 | + $j = ($u[1] - 224 << 12) + ($u[2] - 128 << 6) + $u[3] - 0xac80; | |
| 69 | + if ($t = $j % 28) { | |
| 70 | + $j -= $t; | |
| 71 | + $lv = 0xac00 + $j; | |
| 72 | + $r = \chr(0xe0 | $lv >> 12) . \chr(0x80 | $lv >> 6 & 0x3f) . \chr(0x80 | $lv & 0x3f); | |
| 73 | + $r .= $t < 25 ? "\xe1\x86" . \chr(0xa7 + $t) : "\xe1\x87" . \chr(0x67 + $t); | |
| 74 | + return $r; | |
| 75 | + } | |
| 76 | + return "\xe1\x84" . \chr(0x80 + (int) ($j / 588)) . "\xe1\x85" . \chr(0xa1 + (int) ($j % 588 / 28)); | |
| 77 | + } | |
| 78 | + if (null === self::$rawD) { | |
| 79 | + self::$rawD = self::getData('rawCanonicalDecomposition'); | |
| 80 | + } | |
| 81 | + if (isset(self::$rawD[$s])) { | |
| 82 | + return self::$rawD[$s]; | |
| 83 | + } | |
| 84 | + if (self::NFKC === $form || self::NFKD === $form) { | |
| 85 | + if (null === self::$rawKD) { | |
| 86 | + self::$rawKD = self::getData('rawCompatibilityDecomposition'); | |
| 87 | + } | |
| 88 | + return self::$rawKD[$s] ?? null; | |
| 89 | + } | |
| 90 | + return null; | |
| 91 | + } | |
| 52 | 92 | public static function normalize(string $s, int $form = self::FORM_C) |
| 53 | 93 | { |
| 54 | 94 | if (!preg_match('//u', $s)) { |
| 55 | 95 | return \false; |
| @@ -77,9 +117,10 @@ | ||
| 77 | 117 | } |
| 78 | 118 | if (80000 > \PHP_VERSION_ID) { |
| 79 | 119 | return \false; |
| 80 | 120 | } |
| 81 | - throw new \ValueError('normalizer_normalize(): Argument #2 ($form) must be a a valid normalization form'); | |
| 121 | + // the doubled article was fixed in PHP 8.6 | |
| 122 | + throw new \ValueError('normalizer_normalize(): Argument #2 ($form) must be a ' . (80600 > \PHP_VERSION_ID ? 'a ' : '') . 'valid normalization form'); | |
| 82 | 123 | } |
| 83 | 124 | if ('' === $s) { |
| 84 | 125 | return ''; |
| 85 | 126 | } |