Commaaa2
This commit is contained in:
59
vendor/symfony/string/UnicodeString.php
vendored
59
vendor/symfony/string/UnicodeString.php
vendored
@@ -34,23 +34,32 @@ class UnicodeString extends AbstractUnicodeString
|
||||
{
|
||||
public function __construct(string $string = '')
|
||||
{
|
||||
$this->string = normalizer_is_normalized($string) ? $string : normalizer_normalize($string);
|
||||
if ('' === $string || normalizer_is_normalized($this->string = $string)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (false === $this->string) {
|
||||
if (false === $string = normalizer_normalize($string)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 string.');
|
||||
}
|
||||
|
||||
$this->string = $string;
|
||||
}
|
||||
|
||||
public function append(string ...$suffix): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = $this->string.(1 >= \count($suffix) ? ($suffix[0] ?? '') : implode('', $suffix));
|
||||
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
|
||||
|
||||
if (false === $str->string) {
|
||||
if (normalizer_is_normalized($str->string)) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
if (false === $string = normalizer_normalize($str->string)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 string.');
|
||||
}
|
||||
|
||||
$str->string = $string;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
@@ -139,7 +148,7 @@ class UnicodeString extends AbstractUnicodeString
|
||||
|
||||
try {
|
||||
$i = $this->ignoreCase ? grapheme_stripos($this->string, $needle, $offset) : grapheme_strpos($this->string, $needle, $offset);
|
||||
} catch (\ValueError $e) {
|
||||
} catch (\ValueError) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -176,7 +185,7 @@ class UnicodeString extends AbstractUnicodeString
|
||||
return false === $i ? null : $i;
|
||||
}
|
||||
|
||||
public function join(array $strings, string $lastGlue = null): static
|
||||
public function join(array $strings, ?string $lastGlue = null): static
|
||||
{
|
||||
$str = parent::join($strings, $lastGlue);
|
||||
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
|
||||
@@ -209,12 +218,17 @@ class UnicodeString extends AbstractUnicodeString
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = (1 >= \count($prefix) ? ($prefix[0] ?? '') : implode('', $prefix)).$this->string;
|
||||
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
|
||||
|
||||
if (false === $str->string) {
|
||||
if (normalizer_is_normalized($str->string)) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
if (false === $string = normalizer_normalize($str->string)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 string.');
|
||||
}
|
||||
|
||||
$str->string = $string;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
@@ -235,11 +249,16 @@ class UnicodeString extends AbstractUnicodeString
|
||||
}
|
||||
|
||||
$str->string = $result.$tail;
|
||||
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
|
||||
|
||||
if (false === $str->string) {
|
||||
if (normalizer_is_normalized($str->string)) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
if (false === $string = normalizer_normalize($str->string)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 string.');
|
||||
}
|
||||
|
||||
$str->string = $string;
|
||||
}
|
||||
|
||||
return $str;
|
||||
@@ -253,7 +272,7 @@ class UnicodeString extends AbstractUnicodeString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function slice(int $start = 0, int $length = null): static
|
||||
public function slice(int $start = 0, ?int $length = null): static
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
@@ -262,25 +281,30 @@ class UnicodeString extends AbstractUnicodeString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function splice(string $replacement, int $start = 0, int $length = null): static
|
||||
public function splice(string $replacement, int $start = 0, ?int $length = null): static
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
$start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0;
|
||||
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? 2147483647)) : $length;
|
||||
$str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647);
|
||||
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);
|
||||
|
||||
if (false === $str->string) {
|
||||
if (normalizer_is_normalized($str->string)) {
|
||||
return $str;
|
||||
}
|
||||
|
||||
if (false === $string = normalizer_normalize($str->string)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 string.');
|
||||
}
|
||||
|
||||
$str->string = $string;
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function split(string $delimiter, int $limit = null, int $flags = null): array
|
||||
public function split(string $delimiter, ?int $limit = null, ?int $flags = null): array
|
||||
{
|
||||
if (1 > $limit = $limit ?? 2147483647) {
|
||||
if (1 > $limit ??= 2147483647) {
|
||||
throw new InvalidArgumentException('Split limit must be a positive integer.');
|
||||
}
|
||||
|
||||
@@ -338,6 +362,9 @@ class UnicodeString extends AbstractUnicodeString
|
||||
return $prefix === grapheme_extract($this->string, \strlen($prefix), \GRAPHEME_EXTR_MAXBYTES);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function __wakeup()
|
||||
{
|
||||
if (!\is_string($this->string)) {
|
||||
|
||||
Reference in New Issue
Block a user