| @@ -36,23 +36,23 @@ | ||
| 36 | 36 | * Code subject to the MIT license (https://github.com/hhvm/hsl/blob/master/LICENSE). |
| 37 | 37 | * |
| 38 | 38 | * Copyright (c) 2004-2020, Facebook, Inc. (https://www.facebook.com/) |
| 39 | 39 | */ |
| 40 | - public static function fromRandom(int $length = 16, ?string $alphabet = null) : self | |
| 40 | + public static function fromRandom(int $length = 16, ?string $alphabet = null): self | |
| 41 | 41 | { |
| 42 | 42 | if ($length <= 0) { |
| 43 | - throw new InvalidArgumentException(\sprintf('A strictly positive length is expected, "%d" given.', $length)); | |
| 43 | + throw new InvalidArgumentException(sprintf('A strictly positive length is expected, "%d" given.', $length)); | |
| 44 | 44 | } |
| 45 | 45 | $alphabet = $alphabet ?? self::ALPHABET_ALPHANUMERIC; |
| 46 | 46 | $alphabetSize = \strlen($alphabet); |
| 47 | - $bits = (int) \ceil(\log($alphabetSize, 2.0)); | |
| 47 | + $bits = (int) ceil(log($alphabetSize, 2.0)); | |
| 48 | 48 | if ($bits <= 0 || $bits > 56) { |
| 49 | 49 | throw new InvalidArgumentException('The length of the alphabet must in the [2^1, 2^56] range.'); |
| 50 | 50 | } |
| 51 | 51 | $ret = ''; |
| 52 | 52 | while ($length > 0) { |
| 53 | - $urandomLength = (int) \ceil(2 * $length * $bits / 8.0); | |
| 54 | - $data = \random_bytes($urandomLength); | |
| 53 | + $urandomLength = (int) ceil(2 * $length * $bits / 8.0); | |
| 54 | + $data = random_bytes($urandomLength); | |
| 55 | 55 | $unpackedData = 0; |
| 56 | 56 | $unpackedBits = 0; |
| 57 | 57 | for ($i = 0; $i < $urandomLength && $length > 0; ++$i) { |
| 58 | 58 | // Unpack 8 bits |
| @@ -74,28 +74,28 @@ | ||
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | return new static($ret); |
| 77 | 77 | } |
| 78 | - public function bytesAt(int $offset) : array | |
| 78 | + public function bytesAt(int $offset): array | |
| 79 | 79 | { |
| 80 | 80 | $str = $this->string[$offset] ?? ''; |
| 81 | 81 | return '' === $str ? [] : [\ord($str)]; |
| 82 | 82 | } |
| 83 | - public function append(string ...$suffix) : parent | |
| 83 | + public function append(string ...$suffix): parent | |
| 84 | 84 | { |
| 85 | 85 | $str = clone $this; |
| 86 | - $str->string .= 1 >= \count($suffix) ? $suffix[0] ?? '' : \implode('', $suffix); | |
| 86 | + $str->string .= 1 >= \count($suffix) ? $suffix[0] ?? '' : implode('', $suffix); | |
| 87 | 87 | return $str; |
| 88 | 88 | } |
| 89 | - public function camel() : parent | |
| 89 | + public function camel(): parent | |
| 90 | 90 | { |
| 91 | 91 | $str = clone $this; |
| 92 | - $parts = \explode(' ', \trim(\ucwords(\preg_replace('/[^a-zA-Z0-9\\x7f-\\xff]++/', ' ', $this->string)))); | |
| 93 | - $parts[0] = 1 !== \strlen($parts[0]) && \ctype_upper($parts[0]) ? $parts[0] : \lcfirst($parts[0]); | |
| 94 | - $str->string = \implode('', $parts); | |
| 92 | + $parts = explode(' ', trim(ucwords(preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', ' ', $this->string)))); | |
| 93 | + $parts[0] = 1 !== \strlen($parts[0]) && ctype_upper($parts[0]) ? $parts[0] : lcfirst($parts[0]); | |
| 94 | + $str->string = implode('', $parts); | |
| 95 | 95 | return $str; |
| 96 | 96 | } |
| 97 | - public function chunk(int $length = 1) : array | |
| 97 | + public function chunk(int $length = 1): array | |
| 98 | 98 | { |
| 99 | 99 | if (1 > $length) { |
| 100 | 100 | throw new InvalidArgumentException('The chunk length must be greater than zero.'); |
| 101 | 101 | } |
| @@ -103,15 +103,15 @@ | ||
| 103 | 103 | return []; |
| 104 | 104 | } |
| 105 | 105 | $str = clone $this; |
| 106 | 106 | $chunks = []; |
| 107 | - foreach (\str_split($this->string, $length) as $chunk) { | |
| 107 | + foreach (str_split($this->string, $length) as $chunk) { | |
| 108 | 108 | $str->string = $chunk; |
| 109 | 109 | $chunks[] = clone $str; |
| 110 | 110 | } |
| 111 | 111 | return $chunks; |
| 112 | 112 | } |
| 113 | - public function endsWith($suffix) : bool | |
| 113 | + public function endsWith($suffix): bool | |
| 114 | 114 | { |
| 115 | 115 | if ($suffix instanceof parent) { |
| 116 | 116 | $suffix = $suffix->string; |
| 117 | 117 | } elseif (\is_array($suffix) || $suffix instanceof \Traversable) { |
| @@ -118,11 +118,11 @@ | ||
| 118 | 118 | return parent::endsWith($suffix); |
| 119 | 119 | } else { |
| 120 | 120 | $suffix = (string) $suffix; |
| 121 | 121 | } |
| 122 | - return '' !== $suffix && \strlen($this->string) >= \strlen($suffix) && 0 === \substr_compare($this->string, $suffix, -\strlen($suffix), null, $this->ignoreCase); | |
| 122 | + return '' !== $suffix && \strlen($this->string) >= \strlen($suffix) && 0 === substr_compare($this->string, $suffix, -\strlen($suffix), null, $this->ignoreCase); | |
| 123 | 123 | } |
| 124 | - public function equalsTo($string) : bool | |
| 124 | + public function equalsTo($string): bool | |
| 125 | 125 | { |
| 126 | 126 | if ($string instanceof parent) { |
| 127 | 127 | $string = $string->string; |
| 128 | 128 | } elseif (\is_array($string) || $string instanceof \Traversable) { |
| @@ -130,19 +130,19 @@ | ||
| 130 | 130 | } else { |
| 131 | 131 | $string = (string) $string; |
| 132 | 132 | } |
| 133 | 133 | if ('' !== $string && $this->ignoreCase) { |
| 134 | - return 0 === \strcasecmp($string, $this->string); | |
| 134 | + return 0 === strcasecmp($string, $this->string); | |
| 135 | 135 | } |
| 136 | 136 | return $string === $this->string; |
| 137 | 137 | } |
| 138 | - public function folded() : parent | |
| 138 | + public function folded(): parent | |
| 139 | 139 | { |
| 140 | 140 | $str = clone $this; |
| 141 | - $str->string = \strtolower($str->string); | |
| 141 | + $str->string = strtolower($str->string); | |
| 142 | 142 | return $str; |
| 143 | 143 | } |
| 144 | - public function indexOf($needle, int $offset = 0) : ?int | |
| 144 | + public function indexOf($needle, int $offset = 0): ?int | |
| 145 | 145 | { |
| 146 | 146 | if ($needle instanceof parent) { |
| 147 | 147 | $needle = $needle->string; |
| 148 | 148 | } elseif (\is_array($needle) || $needle instanceof \Traversable) { |
| @@ -152,12 +152,12 @@ | ||
| 152 | 152 | } |
| 153 | 153 | if ('' === $needle) { |
| 154 | 154 | return null; |
| 155 | 155 | } |
| 156 | - $i = $this->ignoreCase ? \stripos($this->string, $needle, $offset) : \strpos($this->string, $needle, $offset); | |
| 156 | + $i = $this->ignoreCase ? stripos($this->string, $needle, $offset) : strpos($this->string, $needle, $offset); | |
| 157 | 157 | return \false === $i ? null : $i; |
| 158 | 158 | } |
| 159 | - public function indexOfLast($needle, int $offset = 0) : ?int | |
| 159 | + public function indexOfLast($needle, int $offset = 0): ?int | |
| 160 | 160 | { |
| 161 | 161 | if ($needle instanceof parent) { |
| 162 | 162 | $needle = $needle->string; |
| 163 | 163 | } elseif (\is_array($needle) || $needle instanceof \Traversable) { |
| @@ -167,46 +167,46 @@ | ||
| 167 | 167 | } |
| 168 | 168 | if ('' === $needle) { |
| 169 | 169 | return null; |
| 170 | 170 | } |
| 171 | - $i = $this->ignoreCase ? \strripos($this->string, $needle, $offset) : \strrpos($this->string, $needle, $offset); | |
| 171 | + $i = $this->ignoreCase ? strripos($this->string, $needle, $offset) : strrpos($this->string, $needle, $offset); | |
| 172 | 172 | return \false === $i ? null : $i; |
| 173 | 173 | } |
| 174 | - public function isUtf8() : bool | |
| 174 | + public function isUtf8(): bool | |
| 175 | 175 | { |
| 176 | - return '' === $this->string || \preg_match('//u', $this->string); | |
| 176 | + return '' === $this->string || preg_match('//u', $this->string); | |
| 177 | 177 | } |
| 178 | - public function join(array $strings, ?string $lastGlue = null) : parent | |
| 178 | + public function join(array $strings, ?string $lastGlue = null): parent | |
| 179 | 179 | { |
| 180 | 180 | $str = clone $this; |
| 181 | - $tail = null !== $lastGlue && 1 < \count($strings) ? $lastGlue . \array_pop($strings) : ''; | |
| 182 | - $str->string = \implode($this->string, $strings) . $tail; | |
| 181 | + $tail = null !== $lastGlue && 1 < \count($strings) ? $lastGlue . array_pop($strings) : ''; | |
| 182 | + $str->string = implode($this->string, $strings) . $tail; | |
| 183 | 183 | return $str; |
| 184 | 184 | } |
| 185 | - public function length() : int | |
| 185 | + public function length(): int | |
| 186 | 186 | { |
| 187 | 187 | return \strlen($this->string); |
| 188 | 188 | } |
| 189 | - public function lower() : parent | |
| 189 | + public function lower(): parent | |
| 190 | 190 | { |
| 191 | 191 | $str = clone $this; |
| 192 | - $str->string = \strtolower($str->string); | |
| 192 | + $str->string = strtolower($str->string); | |
| 193 | 193 | return $str; |
| 194 | 194 | } |
| 195 | - public function match(string $regexp, int $flags = 0, int $offset = 0) : array | |
| 195 | + public function match(string $regexp, int $flags = 0, int $offset = 0): array | |
| 196 | 196 | { |
| 197 | 197 | $match = (\PREG_PATTERN_ORDER | \PREG_SET_ORDER) & $flags ? 'preg_match_all' : 'preg_match'; |
| 198 | 198 | if ($this->ignoreCase) { |
| 199 | 199 | $regexp .= 'i'; |
| 200 | 200 | } |
| 201 | - \set_error_handler(static function ($t, $m) { | |
| 201 | + set_error_handler(static function ($t, $m) { | |
| 202 | 202 | throw new InvalidArgumentException($m); |
| 203 | 203 | }); |
| 204 | 204 | try { |
| 205 | 205 | if (\false === $match($regexp, $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) { |
| 206 | - $lastError = \preg_last_error(); | |
| 207 | - foreach (\get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 208 | - if ($lastError === $v && '_ERROR' === \substr($k, -6)) { | |
| 206 | + $lastError = preg_last_error(); | |
| 207 | + foreach (get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 208 | + if ($lastError === $v && '_ERROR' === substr($k, -6)) { | |
| 209 | 209 | throw new RuntimeException('Matching failed with ' . $k . '.'); |
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | throw new RuntimeException('Matching failed with unknown error code.'); |
| @@ -211,45 +211,45 @@ | ||
| 211 | 211 | } |
| 212 | 212 | throw new RuntimeException('Matching failed with unknown error code.'); |
| 213 | 213 | } |
| 214 | 214 | } finally { |
| 215 | - \restore_error_handler(); | |
| 215 | + restore_error_handler(); | |
| 216 | 216 | } |
| 217 | 217 | return $matches; |
| 218 | 218 | } |
| 219 | - public function padBoth(int $length, string $padStr = ' ') : parent | |
| 219 | + public function padBoth(int $length, string $padStr = ' '): parent | |
| 220 | 220 | { |
| 221 | 221 | $str = clone $this; |
| 222 | - $str->string = \str_pad($this->string, $length, $padStr, \STR_PAD_BOTH); | |
| 222 | + $str->string = str_pad($this->string, $length, $padStr, \STR_PAD_BOTH); | |
| 223 | 223 | return $str; |
| 224 | 224 | } |
| 225 | - public function padEnd(int $length, string $padStr = ' ') : parent | |
| 225 | + public function padEnd(int $length, string $padStr = ' '): parent | |
| 226 | 226 | { |
| 227 | 227 | $str = clone $this; |
| 228 | - $str->string = \str_pad($this->string, $length, $padStr, \STR_PAD_RIGHT); | |
| 228 | + $str->string = str_pad($this->string, $length, $padStr, \STR_PAD_RIGHT); | |
| 229 | 229 | return $str; |
| 230 | 230 | } |
| 231 | - public function padStart(int $length, string $padStr = ' ') : parent | |
| 231 | + public function padStart(int $length, string $padStr = ' '): parent | |
| 232 | 232 | { |
| 233 | 233 | $str = clone $this; |
| 234 | - $str->string = \str_pad($this->string, $length, $padStr, \STR_PAD_LEFT); | |
| 234 | + $str->string = str_pad($this->string, $length, $padStr, \STR_PAD_LEFT); | |
| 235 | 235 | return $str; |
| 236 | 236 | } |
| 237 | - public function prepend(string ...$prefix) : parent | |
| 237 | + public function prepend(string ...$prefix): parent | |
| 238 | 238 | { |
| 239 | 239 | $str = clone $this; |
| 240 | - $str->string = (1 >= \count($prefix) ? $prefix[0] ?? '' : \implode('', $prefix)) . $str->string; | |
| 240 | + $str->string = (1 >= \count($prefix) ? $prefix[0] ?? '' : implode('', $prefix)) . $str->string; | |
| 241 | 241 | return $str; |
| 242 | 242 | } |
| 243 | - public function replace(string $from, string $to) : parent | |
| 243 | + public function replace(string $from, string $to): parent | |
| 244 | 244 | { |
| 245 | 245 | $str = clone $this; |
| 246 | 246 | if ('' !== $from) { |
| 247 | - $str->string = $this->ignoreCase ? \str_ireplace($from, $to, $this->string) : \str_replace($from, $to, $this->string); | |
| 247 | + $str->string = $this->ignoreCase ? str_ireplace($from, $to, $this->string) : str_replace($from, $to, $this->string); | |
| 248 | 248 | } |
| 249 | 249 | return $str; |
| 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,22 +254,22 @@ | ||
| 254 | 254 | $fromRegexp .= 'i'; |
| 255 | 255 | } |
| 256 | 256 | if (\is_array($to)) { |
| 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 | 261 | } else { |
| 262 | 262 | $replace = $to instanceof \Closure ? 'preg_replace_callback' : 'preg_replace'; |
| 263 | 263 | } |
| 264 | - \set_error_handler(static function ($t, $m) { | |
| 264 | + set_error_handler(static function ($t, $m) { | |
| 265 | 265 | throw new InvalidArgumentException($m); |
| 266 | 266 | }); |
| 267 | 267 | try { |
| 268 | - if (null === ($string = $replace($fromRegexp, $to, $this->string))) { | |
| 269 | - $lastError = \preg_last_error(); | |
| 270 | - foreach (\get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 271 | - if ($lastError === $v && '_ERROR' === \substr($k, -6)) { | |
| 268 | + if (null === $string = $replace($fromRegexp, $to, $this->string)) { | |
| 269 | + $lastError = preg_last_error(); | |
| 270 | + foreach (get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 271 | + if ($lastError === $v && '_ERROR' === substr($k, -6)) { | |
| 272 | 272 | throw new RuntimeException('Matching failed with ' . $k . '.'); |
| 273 | 273 | } |
| 274 | 274 | } |
| 275 | 275 | throw new RuntimeException('Matching failed with unknown error code.'); |
| @@ -274,41 +274,41 @@ | ||
| 274 | 274 | } |
| 275 | 275 | throw new RuntimeException('Matching failed with unknown error code.'); |
| 276 | 276 | } |
| 277 | 277 | } finally { |
| 278 | - \restore_error_handler(); | |
| 278 | + restore_error_handler(); | |
| 279 | 279 | } |
| 280 | 280 | $str = clone $this; |
| 281 | 281 | $str->string = $string; |
| 282 | 282 | return $str; |
| 283 | 283 | } |
| 284 | - public function reverse() : parent | |
| 284 | + public function reverse(): parent | |
| 285 | 285 | { |
| 286 | 286 | $str = clone $this; |
| 287 | - $str->string = \strrev($str->string); | |
| 287 | + $str->string = strrev($str->string); | |
| 288 | 288 | return $str; |
| 289 | 289 | } |
| 290 | - public function slice(int $start = 0, ?int $length = null) : parent | |
| 290 | + public function slice(int $start = 0, ?int $length = null): parent | |
| 291 | 291 | { |
| 292 | 292 | $str = clone $this; |
| 293 | - $str->string = (string) \substr($this->string, $start, $length ?? \PHP_INT_MAX); | |
| 293 | + $str->string = (string) substr($this->string, $start, $length ?? \PHP_INT_MAX); | |
| 294 | 294 | return $str; |
| 295 | 295 | } |
| 296 | - public function snake() : parent | |
| 296 | + public function snake(): parent | |
| 297 | 297 | { |
| 298 | 298 | $str = $this->camel(); |
| 299 | - $str->string = \strtolower(\preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\\d])([A-Z])/'], 'WindPressDeps\\1_\\2', $str->string)); | |
| 299 | + $str->string = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $str->string)); | |
| 300 | 300 | return $str; |
| 301 | 301 | } |
| 302 | - public function splice(string $replacement, int $start = 0, ?int $length = null) : parent | |
| 302 | + public function splice(string $replacement, int $start = 0, ?int $length = null): parent | |
| 303 | 303 | { |
| 304 | 304 | $str = clone $this; |
| 305 | - $str->string = \substr_replace($this->string, $replacement, $start, $length ?? \PHP_INT_MAX); | |
| 305 | + $str->string = substr_replace($this->string, $replacement, $start, $length ?? \PHP_INT_MAX); | |
| 306 | 306 | return $str; |
| 307 | 307 | } |
| 308 | - public function split(string $delimiter, ?int $limit = null, ?int $flags = null) : array | |
| 308 | + public function split(string $delimiter, ?int $limit = null, ?int $flags = null): array | |
| 309 | 309 | { |
| 310 | - if (1 > ($limit = $limit ?? \PHP_INT_MAX)) { | |
| 310 | + if (1 > $limit = $limit ?? \PHP_INT_MAX) { | |
| 311 | 311 | throw new InvalidArgumentException('Split limit must be a positive integer.'); |
| 312 | 312 | } |
| 313 | 313 | if ('' === $delimiter) { |
| 314 | 314 | throw new InvalidArgumentException('Split delimiter is empty.'); |
| @@ -316,9 +316,9 @@ | ||
| 316 | 316 | if (null !== $flags) { |
| 317 | 317 | return parent::split($delimiter, $limit, $flags); |
| 318 | 318 | } |
| 319 | 319 | $str = clone $this; |
| 320 | - $chunks = $this->ignoreCase ? \preg_split('{' . \preg_quote($delimiter) . '}iD', $this->string, $limit) : \explode($delimiter, $this->string, $limit); | |
| 320 | + $chunks = $this->ignoreCase ? preg_split('{' . preg_quote($delimiter) . '}iD', $this->string, $limit) : explode($delimiter, $this->string, $limit); | |
| 321 | 321 | foreach ($chunks as &$chunk) { |
| 322 | 322 | $str->string = $chunk; |
| 323 | 323 | $chunk = clone $str; |
| 324 | 324 | } |
| @@ -323,9 +323,9 @@ | ||
| 323 | 323 | $chunk = clone $str; |
| 324 | 324 | } |
| 325 | 325 | return $chunks; |
| 326 | 326 | } |
| 327 | - public function startsWith($prefix) : bool | |
| 327 | + public function startsWith($prefix): bool | |
| 328 | 328 | { |
| 329 | 329 | if ($prefix instanceof parent) { |
| 330 | 330 | $prefix = $prefix->string; |
| 331 | 331 | } elseif (!\is_string($prefix)) { |
| @@ -330,75 +330,75 @@ | ||
| 330 | 330 | $prefix = $prefix->string; |
| 331 | 331 | } elseif (!\is_string($prefix)) { |
| 332 | 332 | return parent::startsWith($prefix); |
| 333 | 333 | } |
| 334 | - return '' !== $prefix && 0 === ($this->ignoreCase ? \strncasecmp($this->string, $prefix, \strlen($prefix)) : \strncmp($this->string, $prefix, \strlen($prefix))); | |
| 334 | + return '' !== $prefix && 0 === ($this->ignoreCase ? strncasecmp($this->string, $prefix, \strlen($prefix)) : strncmp($this->string, $prefix, \strlen($prefix))); | |
| 335 | 335 | } |
| 336 | - public function title(bool $allWords = \false) : parent | |
| 336 | + public function title(bool $allWords = \false): parent | |
| 337 | 337 | { |
| 338 | 338 | $str = clone $this; |
| 339 | - $str->string = $allWords ? \ucwords($str->string) : \ucfirst($str->string); | |
| 339 | + $str->string = $allWords ? ucwords($str->string) : ucfirst($str->string); | |
| 340 | 340 | return $str; |
| 341 | 341 | } |
| 342 | - public function toUnicodeString(?string $fromEncoding = null) : UnicodeString | |
| 342 | + public function toUnicodeString(?string $fromEncoding = null): UnicodeString | |
| 343 | 343 | { |
| 344 | 344 | return new UnicodeString($this->toCodePointString($fromEncoding)->string); |
| 345 | 345 | } |
| 346 | - public function toCodePointString(?string $fromEncoding = null) : CodePointString | |
| 346 | + public function toCodePointString(?string $fromEncoding = null): CodePointString | |
| 347 | 347 | { |
| 348 | 348 | $u = new CodePointString(); |
| 349 | - if (\in_array($fromEncoding, [null, 'utf8', 'utf-8', 'UTF8', 'UTF-8'], \true) && \preg_match('//u', $this->string)) { | |
| 349 | + if (\in_array($fromEncoding, [null, 'utf8', 'utf-8', 'UTF8', 'UTF-8'], \true) && preg_match('//u', $this->string)) { | |
| 350 | 350 | $u->string = $this->string; |
| 351 | 351 | return $u; |
| 352 | 352 | } |
| 353 | - \set_error_handler(static function ($t, $m) { | |
| 353 | + set_error_handler(static function ($t, $m) { | |
| 354 | 354 | throw new InvalidArgumentException($m); |
| 355 | 355 | }); |
| 356 | 356 | try { |
| 357 | 357 | try { |
| 358 | - $validEncoding = \false !== \mb_detect_encoding($this->string, $fromEncoding ?? 'Windows-1252', \true); | |
| 358 | + $validEncoding = \false !== mb_detect_encoding($this->string, $fromEncoding ?? 'Windows-1252', \true); | |
| 359 | 359 | } catch (InvalidArgumentException $e) { |
| 360 | - if (!\function_exists('iconv')) { | |
| 360 | + if (!\function_exists('iconv') && !\function_exists('WindPressDeps\iconv')) { | |
| 361 | 361 | throw $e; |
| 362 | 362 | } |
| 363 | - $u->string = \iconv($fromEncoding ?? 'Windows-1252', 'UTF-8', $this->string); | |
| 363 | + $u->string = iconv($fromEncoding ?? 'Windows-1252', 'UTF-8', $this->string); | |
| 364 | 364 | return $u; |
| 365 | 365 | } |
| 366 | 366 | } finally { |
| 367 | - \restore_error_handler(); | |
| 367 | + restore_error_handler(); | |
| 368 | 368 | } |
| 369 | 369 | if (!$validEncoding) { |
| 370 | - throw new InvalidArgumentException(\sprintf('Invalid "%s" string.', $fromEncoding ?? 'Windows-1252')); | |
| 370 | + throw new InvalidArgumentException(sprintf('Invalid "%s" string.', $fromEncoding ?? 'Windows-1252')); | |
| 371 | 371 | } |
| 372 | - $u->string = \mb_convert_encoding($this->string, 'UTF-8', $fromEncoding ?? 'Windows-1252'); | |
| 372 | + $u->string = mb_convert_encoding($this->string, 'UTF-8', $fromEncoding ?? 'Windows-1252'); | |
| 373 | 373 | return $u; |
| 374 | 374 | } |
| 375 | - public function trim(string $chars = " \t\n\r\x00\v\f") : parent | |
| 375 | + public function trim(string $chars = " \t\n\r\x00\v\f"): parent | |
| 376 | 376 | { |
| 377 | 377 | $str = clone $this; |
| 378 | - $str->string = \trim($str->string, $chars); | |
| 378 | + $str->string = trim($str->string, $chars); | |
| 379 | 379 | return $str; |
| 380 | 380 | } |
| 381 | - public function trimEnd(string $chars = " \t\n\r\x00\v\f") : parent | |
| 381 | + public function trimEnd(string $chars = " \t\n\r\x00\v\f"): parent | |
| 382 | 382 | { |
| 383 | 383 | $str = clone $this; |
| 384 | - $str->string = \rtrim($str->string, $chars); | |
| 384 | + $str->string = rtrim($str->string, $chars); | |
| 385 | 385 | return $str; |
| 386 | 386 | } |
| 387 | - public function trimStart(string $chars = " \t\n\r\x00\v\f") : parent | |
| 387 | + public function trimStart(string $chars = " \t\n\r\x00\v\f"): parent | |
| 388 | 388 | { |
| 389 | 389 | $str = clone $this; |
| 390 | - $str->string = \ltrim($str->string, $chars); | |
| 390 | + $str->string = ltrim($str->string, $chars); | |
| 391 | 391 | return $str; |
| 392 | 392 | } |
| 393 | - public function upper() : parent | |
| 393 | + public function upper(): parent | |
| 394 | 394 | { |
| 395 | 395 | $str = clone $this; |
| 396 | - $str->string = \strtoupper($str->string); | |
| 396 | + $str->string = strtoupper($str->string); | |
| 397 | 397 | return $str; |
| 398 | 398 | } |
| 399 | - public function width(bool $ignoreAnsiDecoration = \true) : int | |
| 399 | + public function width(bool $ignoreAnsiDecoration = \true): int | |
| 400 | 400 | { |
| 401 | - $string = \preg_match('//u', $this->string) ? $this->string : \preg_replace('/[\\x80-\\xFF]/', '?', $this->string); | |
| 401 | + $string = preg_match('//u', $this->string) ? $this->string : preg_replace('/[\x80-\xFF]/', '?', $this->string); | |
| 402 | 402 | return (new CodePointString($string))->width($ignoreAnsiDecoration); |
| 403 | 403 | } |
| 404 | 404 | } |