← All changes
|
vendor/symfony/string/AbstractUnicodeString.php
+122
-122
3.0.13
→
3.2.89
View file →
| @@ -46,13 +46,13 @@ | ||
| 46 | 46 | private static $tableWide; |
| 47 | 47 | /** |
| 48 | 48 | * @return static |
| 49 | 49 | */ |
| 50 | - public static function fromCodePoints(int ...$codes) : self | |
| 50 | + public static function fromCodePoints(int ...$codes): self | |
| 51 | 51 | { |
| 52 | 52 | $string = ''; |
| 53 | 53 | foreach ($codes as $code) { |
| 54 | - if (0x80 > ($code %= 0x200000)) { | |
| 54 | + if (0x80 > $code %= 0x200000) { | |
| 55 | 55 | $string .= \chr($code); |
| 56 | 56 | } elseif (0x800 > $code) { |
| 57 | 57 | $string .= \chr(0xc0 | $code >> 6) . \chr(0x80 | $code & 0x3f); |
| 58 | 58 | } elseif (0x10000 > $code) { |
| @@ -69,14 +69,14 @@ | ||
| 69 | 69 | * Install the intl extension for best results. |
| 70 | 70 | * |
| 71 | 71 | * @param string[]|\Transliterator[]|\Closure[] $rules See "*-Latin" rules from Transliterator::listIDs() |
| 72 | 72 | */ |
| 73 | - public function ascii(array $rules = []) : self | |
| 73 | + public function ascii(array $rules = []): self | |
| 74 | 74 | { |
| 75 | 75 | $str = clone $this; |
| 76 | 76 | $s = $str->string; |
| 77 | 77 | $str->string = ''; |
| 78 | - \array_unshift($rules, 'nfd'); | |
| 78 | + array_unshift($rules, 'nfd'); | |
| 79 | 79 | $rules[] = 'latin-ascii'; |
| 80 | 80 | if (\function_exists('transliterator_transliterate')) { |
| 81 | 81 | $rules[] = 'any-latin/bgn'; |
| 82 | 82 | } |
| @@ -81,14 +81,14 @@ | ||
| 81 | 81 | $rules[] = 'any-latin/bgn'; |
| 82 | 82 | } |
| 83 | 83 | $rules[] = 'nfkd'; |
| 84 | 84 | $rules[] = '[:nonspacing mark:] remove'; |
| 85 | - while (\strlen($s) - 1 > ($i = \strspn($s, self::ASCII))) { | |
| 85 | + while (\strlen($s) - 1 > $i = strspn($s, self::ASCII)) { | |
| 86 | 86 | if (0 < --$i) { |
| 87 | - $str->string .= \substr($s, 0, $i); | |
| 88 | - $s = \substr($s, $i); | |
| 87 | + $str->string .= substr($s, 0, $i); | |
| 88 | + $s = substr($s, $i); | |
| 89 | 89 | } |
| 90 | - if (!($rule = \array_shift($rules))) { | |
| 90 | + if (!$rule = array_shift($rules)) { | |
| 91 | 91 | $rules = []; |
| 92 | 92 | // An empty rule interrupts the next ones |
| 93 | 93 | } |
| 94 | 94 | if ($rule instanceof \Transliterator) { |
| @@ -95,27 +95,27 @@ | ||
| 95 | 95 | $s = $rule->transliterate($s); |
| 96 | 96 | } elseif ($rule instanceof \Closure) { |
| 97 | 97 | $s = $rule($s); |
| 98 | 98 | } elseif ($rule) { |
| 99 | - if ('nfd' === ($rule = \strtolower($rule))) { | |
| 100 | - \normalizer_is_normalized($s, self::NFD) ?: ($s = \normalizer_normalize($s, self::NFD)); | |
| 99 | + if ('nfd' === $rule = strtolower($rule)) { | |
| 100 | + normalizer_is_normalized($s, self::NFD) ?: $s = normalizer_normalize($s, self::NFD); | |
| 101 | 101 | } elseif ('nfkd' === $rule) { |
| 102 | - \normalizer_is_normalized($s, self::NFKD) ?: ($s = \normalizer_normalize($s, self::NFKD)); | |
| 102 | + normalizer_is_normalized($s, self::NFKD) ?: $s = normalizer_normalize($s, self::NFKD); | |
| 103 | 103 | } elseif ('[:nonspacing mark:] remove' === $rule) { |
| 104 | - $s = \preg_replace('/\\p{Mn}++/u', '', $s); | |
| 104 | + $s = preg_replace('/\p{Mn}++/u', '', $s); | |
| 105 | 105 | } elseif ('latin-ascii' === $rule) { |
| 106 | - $s = \str_replace(self::TRANSLIT_FROM, self::TRANSLIT_TO, $s); | |
| 106 | + $s = str_replace(self::TRANSLIT_FROM, self::TRANSLIT_TO, $s); | |
| 107 | 107 | } elseif ('de-ascii' === $rule) { |
| 108 | - $s = \preg_replace("/([AUO])̈(?=\\p{Ll})/u", '$1e', $s); | |
| 109 | - $s = \str_replace(["ä", "ö", "ü", "Ä", "Ö", "Ü"], ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'], $s); | |
| 108 | + $s = preg_replace("/([AUO])̈(?=\\p{Ll})/u", '$1e', $s); | |
| 109 | + $s = str_replace(["ä", "ö", "ü", "Ä", "Ö", "Ü"], ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'], $s); | |
| 110 | 110 | } elseif (\function_exists('transliterator_transliterate')) { |
| 111 | - if (null === ($transliterator = self::$transliterators[$rule] ?? (self::$transliterators[$rule] = \Transliterator::create($rule)))) { | |
| 111 | + if (null === $transliterator = self::$transliterators[$rule] ?? self::$transliterators[$rule] = \Transliterator::create($rule)) { | |
| 112 | 112 | if ('any-latin/bgn' === $rule) { |
| 113 | 113 | $rule = 'any-latin'; |
| 114 | - $transliterator = self::$transliterators[$rule] ?? (self::$transliterators[$rule] = \Transliterator::create($rule)); | |
| 114 | + $transliterator = self::$transliterators[$rule] ?? self::$transliterators[$rule] = \Transliterator::create($rule); | |
| 115 | 115 | } |
| 116 | 116 | if (null === $transliterator) { |
| 117 | - throw new InvalidArgumentException(\sprintf('Unknown transliteration rule "%s".', $rule)); | |
| 117 | + throw new InvalidArgumentException(sprintf('Unknown transliteration rule "%s".', $rule)); | |
| 118 | 118 | } |
| 119 | 119 | self::$transliterators['any-latin/bgn'] = $transliterator; |
| 120 | 120 | } |
| 121 | 121 | $s = $transliterator->transliterate($s); |
| @@ -120,16 +120,16 @@ | ||
| 120 | 120 | } |
| 121 | 121 | $s = $transliterator->transliterate($s); |
| 122 | 122 | } |
| 123 | 123 | } elseif (!\function_exists('iconv')) { |
| 124 | - $s = \preg_replace('/[^\\x00-\\x7F]/u', '?', $s); | |
| 124 | + $s = preg_replace('/[^\x00-\x7F]/u', '?', $s); | |
| 125 | 125 | } else { |
| 126 | - $s = @\preg_replace_callback('/[^\\x00-\\x7F]/u', static function ($c) { | |
| 127 | - $c = (string) \iconv('UTF-8', 'ASCII//TRANSLIT', $c[0]); | |
| 128 | - if ('' === $c && '' === \iconv('UTF-8', 'ASCII//TRANSLIT', '²')) { | |
| 129 | - throw new \LogicException(\sprintf('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you\'re using Alpine Linux.', static::class)); | |
| 126 | + $s = @preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) { | |
| 127 | + $c = (string) iconv('UTF-8', 'ASCII//TRANSLIT', $c[0]); | |
| 128 | + if ('' === $c && '' === iconv('UTF-8', 'ASCII//TRANSLIT', '²')) { | |
| 129 | + throw new \LogicException(sprintf('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you\'re using Alpine Linux.', static::class)); | |
| 130 | 130 | } |
| 131 | - return 1 < \strlen($c) ? \ltrim($c, '\'`"^~') : ('' !== $c ? $c : '?'); | |
| 131 | + return 1 < \strlen($c) ? ltrim($c, '\'`"^~') : ('' !== $c ? $c : '?'); | |
| 132 | 132 | }, $s); |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | $str->string .= $s; |
| @@ -134,20 +134,20 @@ | ||
| 134 | 134 | } |
| 135 | 135 | $str->string .= $s; |
| 136 | 136 | return $str; |
| 137 | 137 | } |
| 138 | - public function camel() : parent | |
| 138 | + public function camel(): parent | |
| 139 | 139 | { |
| 140 | 140 | $str = clone $this; |
| 141 | - $str->string = \str_replace(' ', '', \preg_replace_callback('/\\b.(?!\\p{Lu})/u', static function ($m) use(&$i) { | |
| 142 | - return 1 === ++$i ? 'İ' === $m[0] ? 'i̇' : \mb_strtolower($m[0], 'UTF-8') : \mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8'); | |
| 143 | - }, \preg_replace('/[^\\pL0-9]++/u', ' ', $this->string))); | |
| 141 | + $str->string = str_replace(' ', '', preg_replace_callback('/\b.(?!\p{Lu})/u', static function ($m) use (&$i) { | |
| 142 | + return 1 === ++$i ? 'İ' === $m[0] ? 'i̇' : mb_strtolower($m[0], 'UTF-8') : mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8'); | |
| 143 | + }, preg_replace('/[^\pL0-9]++/u', ' ', $this->string))); | |
| 144 | 144 | return $str; |
| 145 | 145 | } |
| 146 | 146 | /** |
| 147 | 147 | * @return int[] |
| 148 | 148 | */ |
| 149 | - public function codePointsAt(int $offset) : array | |
| 149 | + public function codePointsAt(int $offset): array | |
| 150 | 150 | { |
| 151 | 151 | $str = $this->slice($offset, 1); |
| 152 | 152 | if ('' === $str->string) { |
| 153 | 153 | return []; |
| @@ -152,54 +152,54 @@ | ||
| 152 | 152 | if ('' === $str->string) { |
| 153 | 153 | return []; |
| 154 | 154 | } |
| 155 | 155 | $codePoints = []; |
| 156 | - foreach (\preg_split('//u', $str->string, -1, \PREG_SPLIT_NO_EMPTY) as $c) { | |
| 157 | - $codePoints[] = \mb_ord($c, 'UTF-8'); | |
| 156 | + foreach (preg_split('//u', $str->string, -1, \PREG_SPLIT_NO_EMPTY) as $c) { | |
| 157 | + $codePoints[] = mb_ord($c, 'UTF-8'); | |
| 158 | 158 | } |
| 159 | 159 | return $codePoints; |
| 160 | 160 | } |
| 161 | - public function folded(bool $compat = \true) : parent | |
| 161 | + public function folded(bool $compat = \true): parent | |
| 162 | 162 | { |
| 163 | 163 | $str = clone $this; |
| 164 | - if (!$compat || \PHP_VERSION_ID < 70300 || !\defined('WindPressDeps\\Normalizer::NFKC_CF')) { | |
| 165 | - $str->string = \normalizer_normalize($str->string, $compat ? \Normalizer::NFKC : \Normalizer::NFC); | |
| 166 | - $str->string = \mb_strtolower(\str_replace(self::FOLD_FROM, self::FOLD_TO, $str->string), 'UTF-8'); | |
| 164 | + if (!$compat || \PHP_VERSION_ID < 70300 || !\defined('WindPressDeps\Normalizer::NFKC_CF')) { | |
| 165 | + $str->string = normalizer_normalize($str->string, $compat ? \Normalizer::NFKC : \Normalizer::NFC); | |
| 166 | + $str->string = mb_strtolower(str_replace(self::FOLD_FROM, self::FOLD_TO, $str->string), 'UTF-8'); | |
| 167 | 167 | } else { |
| 168 | - $str->string = \normalizer_normalize($str->string, \Normalizer::NFKC_CF); | |
| 168 | + $str->string = normalizer_normalize($str->string, \Normalizer::NFKC_CF); | |
| 169 | 169 | } |
| 170 | 170 | return $str; |
| 171 | 171 | } |
| 172 | - public function join(array $strings, ?string $lastGlue = null) : parent | |
| 172 | + public function join(array $strings, ?string $lastGlue = null): parent | |
| 173 | 173 | { |
| 174 | 174 | $str = clone $this; |
| 175 | - $tail = null !== $lastGlue && 1 < \count($strings) ? $lastGlue . \array_pop($strings) : ''; | |
| 176 | - $str->string = \implode($this->string, $strings) . $tail; | |
| 177 | - if (!\preg_match('//u', $str->string)) { | |
| 175 | + $tail = null !== $lastGlue && 1 < \count($strings) ? $lastGlue . array_pop($strings) : ''; | |
| 176 | + $str->string = implode($this->string, $strings) . $tail; | |
| 177 | + if (!preg_match('//u', $str->string)) { | |
| 178 | 178 | throw new InvalidArgumentException('Invalid UTF-8 string.'); |
| 179 | 179 | } |
| 180 | 180 | return $str; |
| 181 | 181 | } |
| 182 | - public function lower() : parent | |
| 182 | + public function lower(): parent | |
| 183 | 183 | { |
| 184 | 184 | $str = clone $this; |
| 185 | - $str->string = \mb_strtolower(\str_replace('İ', 'i̇', $str->string), 'UTF-8'); | |
| 185 | + $str->string = mb_strtolower(str_replace('İ', 'i̇', $str->string), 'UTF-8'); | |
| 186 | 186 | return $str; |
| 187 | 187 | } |
| 188 | - public function match(string $regexp, int $flags = 0, int $offset = 0) : array | |
| 188 | + public function match(string $regexp, int $flags = 0, int $offset = 0): array | |
| 189 | 189 | { |
| 190 | 190 | $match = (\PREG_PATTERN_ORDER | \PREG_SET_ORDER) & $flags ? 'preg_match_all' : 'preg_match'; |
| 191 | 191 | if ($this->ignoreCase) { |
| 192 | 192 | $regexp .= 'i'; |
| 193 | 193 | } |
| 194 | - \set_error_handler(static function ($t, $m) { | |
| 194 | + set_error_handler(static function ($t, $m) { | |
| 195 | 195 | throw new InvalidArgumentException($m); |
| 196 | 196 | }); |
| 197 | 197 | try { |
| 198 | 198 | if (\false === $match($regexp . 'u', $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) { |
| 199 | - $lastError = \preg_last_error(); | |
| 200 | - foreach (\get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 201 | - if ($lastError === $v && '_ERROR' === \substr($k, -6)) { | |
| 199 | + $lastError = preg_last_error(); | |
| 200 | + foreach (get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 201 | + if ($lastError === $v && '_ERROR' === substr($k, -6)) { | |
| 202 | 202 | throw new RuntimeException('Matching failed with ' . $k . '.'); |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | throw new RuntimeException('Matching failed with unknown error code.'); |
| @@ -204,9 +204,9 @@ | ||
| 204 | 204 | } |
| 205 | 205 | throw new RuntimeException('Matching failed with unknown error code.'); |
| 206 | 206 | } |
| 207 | 207 | } finally { |
| 208 | - \restore_error_handler(); | |
| 208 | + restore_error_handler(); | |
| 209 | 209 | } |
| 210 | 210 | return $matches; |
| 211 | 211 | } |
| 212 | 212 | /** |
| @@ -211,20 +211,20 @@ | ||
| 211 | 211 | } |
| 212 | 212 | /** |
| 213 | 213 | * @return static |
| 214 | 214 | */ |
| 215 | - public function normalize(int $form = self::NFC) : self | |
| 215 | + public function normalize(int $form = self::NFC): self | |
| 216 | 216 | { |
| 217 | 217 | if (!\in_array($form, [self::NFC, self::NFD, self::NFKC, self::NFKD])) { |
| 218 | 218 | throw new InvalidArgumentException('Unsupported normalization form.'); |
| 219 | 219 | } |
| 220 | 220 | $str = clone $this; |
| 221 | - \normalizer_is_normalized($str->string, $form) ?: ($str->string = \normalizer_normalize($str->string, $form)); | |
| 221 | + normalizer_is_normalized($str->string, $form) ?: $str->string = normalizer_normalize($str->string, $form); | |
| 222 | 222 | return $str; |
| 223 | 223 | } |
| 224 | - public function padBoth(int $length, string $padStr = ' ') : parent | |
| 224 | + public function padBoth(int $length, string $padStr = ' '): parent | |
| 225 | 225 | { |
| 226 | - if ('' === $padStr || !\preg_match('//u', $padStr)) { | |
| 226 | + if ('' === $padStr || !preg_match('//u', $padStr)) { | |
| 227 | 227 | throw new InvalidArgumentException('Invalid UTF-8 string.'); |
| 228 | 228 | } |
| 229 | 229 | $pad = clone $this; |
| 230 | 230 | $pad->string = $padStr; |
| @@ -229,11 +229,11 @@ | ||
| 229 | 229 | $pad = clone $this; |
| 230 | 230 | $pad->string = $padStr; |
| 231 | 231 | return $this->pad($length, $pad, \STR_PAD_BOTH); |
| 232 | 232 | } |
| 233 | - public function padEnd(int $length, string $padStr = ' ') : parent | |
| 233 | + public function padEnd(int $length, string $padStr = ' '): parent | |
| 234 | 234 | { |
| 235 | - if ('' === $padStr || !\preg_match('//u', $padStr)) { | |
| 235 | + if ('' === $padStr || !preg_match('//u', $padStr)) { | |
| 236 | 236 | throw new InvalidArgumentException('Invalid UTF-8 string.'); |
| 237 | 237 | } |
| 238 | 238 | $pad = clone $this; |
| 239 | 239 | $pad->string = $padStr; |
| @@ -238,11 +238,11 @@ | ||
| 238 | 238 | $pad = clone $this; |
| 239 | 239 | $pad->string = $padStr; |
| 240 | 240 | return $this->pad($length, $pad, \STR_PAD_RIGHT); |
| 241 | 241 | } |
| 242 | - public function padStart(int $length, string $padStr = ' ') : parent | |
| 242 | + public function padStart(int $length, string $padStr = ' '): parent | |
| 243 | 243 | { |
| 244 | - if ('' === $padStr || !\preg_match('//u', $padStr)) { | |
| 244 | + if ('' === $padStr || !preg_match('//u', $padStr)) { | |
| 245 | 245 | throw new InvalidArgumentException('Invalid UTF-8 string.'); |
| 246 | 246 | } |
| 247 | 247 | $pad = clone $this; |
| 248 | 248 | $pad->string = $padStr; |
| @@ -247,9 +247,9 @@ | ||
| 247 | 247 | $pad = clone $this; |
| 248 | 248 | $pad->string = $padStr; |
| 249 | 249 | return $this->pad($length, $pad, \STR_PAD_LEFT); |
| 250 | 250 | } |
| 251 | - public function replaceMatches(string $fromRegexp, $to) : parent | |
| 251 | + public function replaceMatches(string $fromRegexp, $to): parent | |
| 252 | 252 | { |
| 253 | 253 | if ($this->ignoreCase) { |
| 254 | 254 | $fromRegexp .= 'i'; |
| 255 | 255 | } |
| @@ -254,31 +254,31 @@ | ||
| 254 | 254 | $fromRegexp .= 'i'; |
| 255 | 255 | } |
| 256 | 256 | if (\is_array($to) || $to instanceof \Closure) { |
| 257 | 257 | if (!\is_callable($to)) { |
| 258 | - throw new \TypeError(\sprintf('Argument 2 passed to "%s::replaceMatches()" must be callable, array given.', static::class)); | |
| 258 | + throw new \TypeError(sprintf('Argument 2 passed to "%s::replaceMatches()" must be callable, array given.', static::class)); | |
| 259 | 259 | } |
| 260 | 260 | $replace = 'preg_replace_callback'; |
| 261 | - $to = static function (array $m) use($to) : string { | |
| 261 | + $to = static function (array $m) use ($to): string { | |
| 262 | 262 | $to = $to($m); |
| 263 | - if ('' !== $to && (!\is_string($to) || !\preg_match('//u', $to))) { | |
| 263 | + if ('' !== $to && (!\is_string($to) || !preg_match('//u', $to))) { | |
| 264 | 264 | throw new InvalidArgumentException('Replace callback must return a valid UTF-8 string.'); |
| 265 | 265 | } |
| 266 | 266 | return $to; |
| 267 | 267 | }; |
| 268 | - } elseif ('' !== $to && !\preg_match('//u', $to)) { | |
| 268 | + } elseif ('' !== $to && !preg_match('//u', $to)) { | |
| 269 | 269 | throw new InvalidArgumentException('Invalid UTF-8 string.'); |
| 270 | 270 | } else { |
| 271 | 271 | $replace = 'preg_replace'; |
| 272 | 272 | } |
| 273 | - \set_error_handler(static function ($t, $m) { | |
| 273 | + set_error_handler(static function ($t, $m) { | |
| 274 | 274 | throw new InvalidArgumentException($m); |
| 275 | 275 | }); |
| 276 | 276 | try { |
| 277 | - if (null === ($string = $replace($fromRegexp . 'u', $to, $this->string))) { | |
| 278 | - $lastError = \preg_last_error(); | |
| 279 | - foreach (\get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 280 | - if ($lastError === $v && '_ERROR' === \substr($k, -6)) { | |
| 277 | + if (null === $string = $replace($fromRegexp . 'u', $to, $this->string)) { | |
| 278 | + $lastError = preg_last_error(); | |
| 279 | + foreach (get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 280 | + if ($lastError === $v && '_ERROR' === substr($k, -6)) { | |
| 281 | 281 | throw new RuntimeException('Matching failed with ' . $k . '.'); |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | throw new RuntimeException('Matching failed with unknown error code.'); |
| @@ -283,56 +283,56 @@ | ||
| 283 | 283 | } |
| 284 | 284 | throw new RuntimeException('Matching failed with unknown error code.'); |
| 285 | 285 | } |
| 286 | 286 | } finally { |
| 287 | - \restore_error_handler(); | |
| 287 | + restore_error_handler(); | |
| 288 | 288 | } |
| 289 | 289 | $str = clone $this; |
| 290 | 290 | $str->string = $string; |
| 291 | 291 | return $str; |
| 292 | 292 | } |
| 293 | - public function reverse() : parent | |
| 293 | + public function reverse(): parent | |
| 294 | 294 | { |
| 295 | 295 | $str = clone $this; |
| 296 | - $str->string = \implode('', \array_reverse(\preg_split('/(\\X)/u', $str->string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY))); | |
| 296 | + $str->string = implode('', array_reverse(preg_split('/(\X)/u', $str->string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY))); | |
| 297 | 297 | return $str; |
| 298 | 298 | } |
| 299 | - public function snake() : parent | |
| 299 | + public function snake(): parent | |
| 300 | 300 | { |
| 301 | 301 | $str = $this->camel(); |
| 302 | - $str->string = \mb_strtolower(\preg_replace(['/(\\p{Lu}+)(\\p{Lu}\\p{Ll})/u', '/([\\p{Ll}0-9])(\\p{Lu})/u'], 'WindPressDeps\\1_\\2', $str->string), 'UTF-8'); | |
| 302 | + $str->string = mb_strtolower(preg_replace(['/(\p{Lu}+)(\p{Lu}\p{Ll})/u', '/([\p{Ll}0-9])(\p{Lu})/u'], '\1_\2', $str->string), 'UTF-8'); | |
| 303 | 303 | return $str; |
| 304 | 304 | } |
| 305 | - public function title(bool $allWords = \false) : parent | |
| 305 | + public function title(bool $allWords = \false): parent | |
| 306 | 306 | { |
| 307 | 307 | $str = clone $this; |
| 308 | 308 | $limit = $allWords ? -1 : 1; |
| 309 | - $str->string = \preg_replace_callback('/\\b./u', static function (array $m) : string { | |
| 310 | - return \mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8'); | |
| 309 | + $str->string = preg_replace_callback('/\b./u', static function (array $m): string { | |
| 310 | + return mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8'); | |
| 311 | 311 | }, $str->string, $limit); |
| 312 | 312 | return $str; |
| 313 | 313 | } |
| 314 | - public function trim(string $chars = " \t\n\r\x00\v\f ") : parent | |
| 314 | + public function trim(string $chars = " \t\n\r\x00\v\f "): parent | |
| 315 | 315 | { |
| 316 | - if (" \t\n\r\x00\v\f " !== $chars && !\preg_match('//u', $chars)) { | |
| 316 | + if (" \t\n\r\x00\v\f " !== $chars && !preg_match('//u', $chars)) { | |
| 317 | 317 | throw new InvalidArgumentException('Invalid UTF-8 chars.'); |
| 318 | 318 | } |
| 319 | - $chars = \preg_quote($chars); | |
| 319 | + $chars = preg_quote($chars); | |
| 320 | 320 | $str = clone $this; |
| 321 | - $str->string = \preg_replace("{^[{$chars}]++|[{$chars}]++\$}uD", '', $str->string); | |
| 321 | + $str->string = preg_replace("{^[{$chars}]++|[{$chars}]++\$}uD", '', $str->string); | |
| 322 | 322 | return $str; |
| 323 | 323 | } |
| 324 | - public function trimEnd(string $chars = " \t\n\r\x00\v\f ") : parent | |
| 324 | + public function trimEnd(string $chars = " \t\n\r\x00\v\f "): parent | |
| 325 | 325 | { |
| 326 | - if (" \t\n\r\x00\v\f " !== $chars && !\preg_match('//u', $chars)) { | |
| 326 | + if (" \t\n\r\x00\v\f " !== $chars && !preg_match('//u', $chars)) { | |
| 327 | 327 | throw new InvalidArgumentException('Invalid UTF-8 chars.'); |
| 328 | 328 | } |
| 329 | - $chars = \preg_quote($chars); | |
| 329 | + $chars = preg_quote($chars); | |
| 330 | 330 | $str = clone $this; |
| 331 | - $str->string = \preg_replace("{[{$chars}]++\$}uD", '', $str->string); | |
| 331 | + $str->string = preg_replace("{[{$chars}]++\$}uD", '', $str->string); | |
| 332 | 332 | return $str; |
| 333 | 333 | } |
| 334 | - public function trimPrefix($prefix) : parent | |
| 334 | + public function trimPrefix($prefix): parent | |
| 335 | 335 | { |
| 336 | 336 | if (!$this->ignoreCase) { |
| 337 | 337 | return parent::trimPrefix($prefix); |
| 338 | 338 | } |
| @@ -337,27 +337,27 @@ | ||
| 337 | 337 | return parent::trimPrefix($prefix); |
| 338 | 338 | } |
| 339 | 339 | $str = clone $this; |
| 340 | 340 | if ($prefix instanceof \Traversable) { |
| 341 | - $prefix = \iterator_to_array($prefix, \false); | |
| 341 | + $prefix = iterator_to_array($prefix, \false); | |
| 342 | 342 | } elseif ($prefix instanceof parent) { |
| 343 | 343 | $prefix = $prefix->string; |
| 344 | 344 | } |
| 345 | - $prefix = \implode('|', \array_map('preg_quote', (array) $prefix)); | |
| 346 | - $str->string = \preg_replace("{^(?:{$prefix})}iuD", '', $this->string); | |
| 345 | + $prefix = implode('|', array_map('preg_quote', (array) $prefix)); | |
| 346 | + $str->string = preg_replace("{^(?:{$prefix})}iuD", '', $this->string); | |
| 347 | 347 | return $str; |
| 348 | 348 | } |
| 349 | - public function trimStart(string $chars = " \t\n\r\x00\v\f ") : parent | |
| 349 | + public function trimStart(string $chars = " \t\n\r\x00\v\f "): parent | |
| 350 | 350 | { |
| 351 | - if (" \t\n\r\x00\v\f " !== $chars && !\preg_match('//u', $chars)) { | |
| 351 | + if (" \t\n\r\x00\v\f " !== $chars && !preg_match('//u', $chars)) { | |
| 352 | 352 | throw new InvalidArgumentException('Invalid UTF-8 chars.'); |
| 353 | 353 | } |
| 354 | - $chars = \preg_quote($chars); | |
| 354 | + $chars = preg_quote($chars); | |
| 355 | 355 | $str = clone $this; |
| 356 | - $str->string = \preg_replace("{^[{$chars}]++}uD", '', $str->string); | |
| 356 | + $str->string = preg_replace("{^[{$chars}]++}uD", '', $str->string); | |
| 357 | 357 | return $str; |
| 358 | 358 | } |
| 359 | - public function trimSuffix($suffix) : parent | |
| 359 | + public function trimSuffix($suffix): parent | |
| 360 | 360 | { |
| 361 | 361 | if (!$this->ignoreCase) { |
| 362 | 362 | return parent::trimSuffix($suffix); |
| 363 | 363 | } |
| @@ -362,42 +362,42 @@ | ||
| 362 | 362 | return parent::trimSuffix($suffix); |
| 363 | 363 | } |
| 364 | 364 | $str = clone $this; |
| 365 | 365 | if ($suffix instanceof \Traversable) { |
| 366 | - $suffix = \iterator_to_array($suffix, \false); | |
| 366 | + $suffix = iterator_to_array($suffix, \false); | |
| 367 | 367 | } elseif ($suffix instanceof parent) { |
| 368 | 368 | $suffix = $suffix->string; |
| 369 | 369 | } |
| 370 | - $suffix = \implode('|', \array_map('preg_quote', (array) $suffix)); | |
| 371 | - $str->string = \preg_replace("{(?:{$suffix})\$}iuD", '', $this->string); | |
| 370 | + $suffix = implode('|', array_map('preg_quote', (array) $suffix)); | |
| 371 | + $str->string = preg_replace("{(?:{$suffix})\$}iuD", '', $this->string); | |
| 372 | 372 | return $str; |
| 373 | 373 | } |
| 374 | - public function upper() : parent | |
| 374 | + public function upper(): parent | |
| 375 | 375 | { |
| 376 | 376 | $str = clone $this; |
| 377 | - $str->string = \mb_strtoupper($str->string, 'UTF-8'); | |
| 377 | + $str->string = mb_strtoupper($str->string, 'UTF-8'); | |
| 378 | 378 | if (\PHP_VERSION_ID < 70300) { |
| 379 | - $str->string = \str_replace(self::UPPER_FROM, self::UPPER_TO, $str->string); | |
| 379 | + $str->string = str_replace(self::UPPER_FROM, self::UPPER_TO, $str->string); | |
| 380 | 380 | } |
| 381 | 381 | return $str; |
| 382 | 382 | } |
| 383 | - public function width(bool $ignoreAnsiDecoration = \true) : int | |
| 383 | + public function width(bool $ignoreAnsiDecoration = \true): int | |
| 384 | 384 | { |
| 385 | 385 | $width = 0; |
| 386 | - $s = \str_replace(["\x00", "\x05", "\x07"], '', $this->string); | |
| 387 | - if (\false !== \strpos($s, "\r")) { | |
| 388 | - $s = \str_replace(["\r\n", "\r"], "\n", $s); | |
| 386 | + $s = str_replace(["\x00", "\x05", "\x07"], '', $this->string); | |
| 387 | + if (\false !== strpos($s, "\r")) { | |
| 388 | + $s = str_replace(["\r\n", "\r"], "\n", $s); | |
| 389 | 389 | } |
| 390 | 390 | if (!$ignoreAnsiDecoration) { |
| 391 | - $s = \preg_replace('/[\\p{Cc}\\x7F]++/u', '', $s); | |
| 391 | + $s = preg_replace('/[\p{Cc}\x7F]++/u', '', $s); | |
| 392 | 392 | } |
| 393 | - foreach (\explode("\n", $s) as $s) { | |
| 393 | + foreach (explode("\n", $s) as $s) { | |
| 394 | 394 | if ($ignoreAnsiDecoration) { |
| 395 | - $s = \preg_replace('/(?:\\x1B(?: | |
| 396 | - \\[ [\\x30-\\x3F]*+ [\\x20-\\x2F]*+ [\\x40-\\x7E] | |
| 397 | - | [P\\]X^_] .*? \\x1B\\\\ | |
| 398 | - | [\\x41-\\x7E] | |
| 399 | - )|[\\p{Cc}\\x7F]++)/xu', '', $s); | |
| 395 | + $s = preg_replace('/(?:\x1B(?: | |
| 396 | + \[ [\x30-\x3F]*+ [\x20-\x2F]*+ [\x40-\x7E] | |
| 397 | + | [P\]X^_] .*? \x1B\\\\ | |
| 398 | + | [\x41-\x7E] | |
| 399 | + )|[\p{Cc}\x7F]++)/xu', '', $s); | |
| 400 | 400 | } |
| 401 | 401 | $lineWidth = $this->wcswidth($s); |
| 402 | 402 | if ($lineWidth > $width) { |
| 403 | 403 | $width = $lineWidth; |
| @@ -407,9 +407,9 @@ | ||
| 407 | 407 | } |
| 408 | 408 | /** |
| 409 | 409 | * @return static |
| 410 | 410 | */ |
| 411 | - private function pad(int $len, self $pad, int $type) : parent | |
| 411 | + private function pad(int $len, self $pad, int $type): parent | |
| 412 | 412 | { |
| 413 | 413 | $sLen = $this->length(); |
| 414 | 414 | if ($len <= $sLen) { |
| 415 | 415 | return clone $this; |
| @@ -418,19 +418,19 @@ | ||
| 418 | 418 | $freeLen = $len - $sLen; |
| 419 | 419 | $len = $freeLen % $padLen; |
| 420 | 420 | switch ($type) { |
| 421 | 421 | case \STR_PAD_RIGHT: |
| 422 | - return $this->append(\str_repeat($pad->string, \intdiv($freeLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); | |
| 422 | + return $this->append(str_repeat($pad->string, intdiv($freeLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); | |
| 423 | 423 | case \STR_PAD_LEFT: |
| 424 | - return $this->prepend(\str_repeat($pad->string, \intdiv($freeLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); | |
| 424 | + return $this->prepend(str_repeat($pad->string, intdiv($freeLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); | |
| 425 | 425 | case \STR_PAD_BOTH: |
| 426 | 426 | $freeLen /= 2; |
| 427 | - $rightLen = \ceil($freeLen); | |
| 427 | + $rightLen = ceil($freeLen); | |
| 428 | 428 | $len = $rightLen % $padLen; |
| 429 | - $str = $this->append(\str_repeat($pad->string, \intdiv($rightLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); | |
| 430 | - $leftLen = \floor($freeLen); | |
| 429 | + $str = $this->append(str_repeat($pad->string, intdiv($rightLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); | |
| 430 | + $leftLen = floor($freeLen); | |
| 431 | 431 | $len = $leftLen % $padLen; |
| 432 | - return $str->prepend(\str_repeat($pad->string, \intdiv($leftLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); | |
| 432 | + return $str->prepend(str_repeat($pad->string, intdiv($leftLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); | |
| 433 | 433 | default: |
| 434 | 434 | throw new InvalidArgumentException('Invalid padding type.'); |
| 435 | 435 | } |
| 436 | 436 | } |
| @@ -436,13 +436,13 @@ | ||
| 436 | 436 | } |
| 437 | 437 | /** |
| 438 | 438 | * Based on https://github.com/jquast/wcwidth, a Python implementation of https://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c. |
| 439 | 439 | */ |
| 440 | - private function wcswidth(string $string) : int | |
| 440 | + private function wcswidth(string $string): int | |
| 441 | 441 | { |
| 442 | 442 | $width = 0; |
| 443 | - foreach (\preg_split('//u', $string, -1, \PREG_SPLIT_NO_EMPTY) as $c) { | |
| 444 | - $codePoint = \mb_ord($c, 'UTF-8'); | |
| 443 | + foreach (preg_split('//u', $string, -1, \PREG_SPLIT_NO_EMPTY) as $c) { | |
| 444 | + $codePoint = mb_ord($c, 'UTF-8'); | |
| 445 | 445 | if (0 === $codePoint || 0x34f === $codePoint || 0x200b <= $codePoint && 0x200f >= $codePoint || 0x2028 === $codePoint || 0x2029 === $codePoint || 0x202a <= $codePoint && 0x202e >= $codePoint || 0x2060 <= $codePoint && 0x2063 >= $codePoint) { |
| 446 | 446 | continue; |
| 447 | 447 | } |
| 448 | 448 | // Non printable characters |
| @@ -449,14 +449,14 @@ | ||
| 449 | 449 | if (32 > $codePoint || 0x7f <= $codePoint && 0xa0 > $codePoint) { |
| 450 | 450 | return -1; |
| 451 | 451 | } |
| 452 | 452 | if (null === self::$tableZero) { |
| 453 | - self::$tableZero = (require __DIR__ . '/Resources/data/wcswidth_table_zero.php'); | |
| 453 | + self::$tableZero = require __DIR__ . '/Resources/data/wcswidth_table_zero.php'; | |
| 454 | 454 | } |
| 455 | 455 | if ($codePoint >= self::$tableZero[0][0] && $codePoint <= self::$tableZero[$ubound = \count(self::$tableZero) - 1][1]) { |
| 456 | 456 | $lbound = 0; |
| 457 | 457 | while ($ubound >= $lbound) { |
| 458 | - $mid = \floor(($lbound + $ubound) / 2); | |
| 458 | + $mid = floor(($lbound + $ubound) / 2); | |
| 459 | 459 | if ($codePoint > self::$tableZero[$mid][1]) { |
| 460 | 460 | $lbound = $mid + 1; |
| 461 | 461 | } elseif ($codePoint < self::$tableZero[$mid][0]) { |
| 462 | 462 | $ubound = $mid - 1; |
| @@ -465,14 +465,14 @@ | ||
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | if (null === self::$tableWide) { |
| 469 | - self::$tableWide = (require __DIR__ . '/Resources/data/wcswidth_table_wide.php'); | |
| 469 | + self::$tableWide = require __DIR__ . '/Resources/data/wcswidth_table_wide.php'; | |
| 470 | 470 | } |
| 471 | 471 | if ($codePoint >= self::$tableWide[0][0] && $codePoint <= self::$tableWide[$ubound = \count(self::$tableWide) - 1][1]) { |
| 472 | 472 | $lbound = 0; |
| 473 | 473 | while ($ubound >= $lbound) { |
| 474 | - $mid = \floor(($lbound + $ubound) / 2); | |
| 474 | + $mid = floor(($lbound + $ubound) / 2); | |
| 475 | 475 | if ($codePoint > self::$tableWide[$mid][1]) { |
| 476 | 476 | $lbound = $mid + 1; |
| 477 | 477 | } elseif ($codePoint < self::$tableWide[$mid][0]) { |
| 478 | 478 | $ubound = $mid - 1; |