package and depencies
This commit is contained in:
85
vendor/symfony/string/AbstractUnicodeString.php
vendored
85
vendor/symfony/string/AbstractUnicodeString.php
vendored
@@ -52,10 +52,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
private static $tableZero;
|
||||
private static $tableWide;
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function fromCodePoints(int ...$codes): self
|
||||
public static function fromCodePoints(int ...$codes): static
|
||||
{
|
||||
$string = '';
|
||||
|
||||
@@ -124,10 +121,10 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
$s = preg_replace("/([AUO])\u{0308}(?=\p{Ll})/u", '$1e', $s);
|
||||
$s = str_replace(["a\u{0308}", "o\u{0308}", "u\u{0308}", "A\u{0308}", "O\u{0308}", "U\u{0308}"], ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'], $s);
|
||||
} elseif (\function_exists('transliterator_transliterate')) {
|
||||
if (null === $transliterator = self::$transliterators[$rule] ?? self::$transliterators[$rule] = \Transliterator::create($rule)) {
|
||||
if (null === $transliterator = self::$transliterators[$rule] ??= \Transliterator::create($rule)) {
|
||||
if ('any-latin/bgn' === $rule) {
|
||||
$rule = 'any-latin';
|
||||
$transliterator = self::$transliterators[$rule] ?? self::$transliterators[$rule] = \Transliterator::create($rule);
|
||||
$transliterator = self::$transliterators[$rule] ??= \Transliterator::create($rule);
|
||||
}
|
||||
|
||||
if (null === $transliterator) {
|
||||
@@ -159,7 +156,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function camel(): parent
|
||||
public function camel(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = str_replace(' ', '', preg_replace_callback('/\b.(?![A-Z]{2,})/u', static function ($m) use (&$i) {
|
||||
@@ -189,11 +186,11 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $codePoints;
|
||||
}
|
||||
|
||||
public function folded(bool $compat = true): parent
|
||||
public function folded(bool $compat = true): static
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
if (!$compat || \PHP_VERSION_ID < 70300 || !\defined('Normalizer::NFKC_CF')) {
|
||||
if (!$compat || !\defined('Normalizer::NFKC_CF')) {
|
||||
$str->string = normalizer_normalize($str->string, $compat ? \Normalizer::NFKC : \Normalizer::NFC);
|
||||
$str->string = mb_strtolower(str_replace(self::FOLD_FROM, self::FOLD_TO, $this->string), 'UTF-8');
|
||||
} else {
|
||||
@@ -203,7 +200,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function join(array $strings, string $lastGlue = null): parent
|
||||
public function join(array $strings, string $lastGlue = null): static
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
@@ -217,7 +214,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function lower(): parent
|
||||
public function lower(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = mb_strtolower(str_replace('İ', 'i̇', $str->string), 'UTF-8');
|
||||
@@ -237,15 +234,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
|
||||
try {
|
||||
if (false === $match($regexp.'u', $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) {
|
||||
$lastError = preg_last_error();
|
||||
|
||||
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
|
||||
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
|
||||
throw new RuntimeException('Matching failed with '.$k.'.');
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException('Matching failed with unknown error code.');
|
||||
throw new RuntimeException('Matching failed with error: '.preg_last_error_msg());
|
||||
}
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
@@ -254,10 +243,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public function normalize(int $form = self::NFC): self
|
||||
public function normalize(int $form = self::NFC): static
|
||||
{
|
||||
if (!\in_array($form, [self::NFC, self::NFD, self::NFKC, self::NFKD])) {
|
||||
throw new InvalidArgumentException('Unsupported normalization form.');
|
||||
@@ -269,7 +255,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function padBoth(int $length, string $padStr = ' '): parent
|
||||
public function padBoth(int $length, string $padStr = ' '): static
|
||||
{
|
||||
if ('' === $padStr || !preg_match('//u', $padStr)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 string.');
|
||||
@@ -281,7 +267,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $this->pad($length, $pad, \STR_PAD_BOTH);
|
||||
}
|
||||
|
||||
public function padEnd(int $length, string $padStr = ' '): parent
|
||||
public function padEnd(int $length, string $padStr = ' '): static
|
||||
{
|
||||
if ('' === $padStr || !preg_match('//u', $padStr)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 string.');
|
||||
@@ -293,7 +279,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $this->pad($length, $pad, \STR_PAD_RIGHT);
|
||||
}
|
||||
|
||||
public function padStart(int $length, string $padStr = ' '): parent
|
||||
public function padStart(int $length, string $padStr = ' '): static
|
||||
{
|
||||
if ('' === $padStr || !preg_match('//u', $padStr)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 string.');
|
||||
@@ -305,17 +291,13 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $this->pad($length, $pad, \STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public function replaceMatches(string $fromRegexp, $to): parent
|
||||
public function replaceMatches(string $fromRegexp, string|callable $to): static
|
||||
{
|
||||
if ($this->ignoreCase) {
|
||||
$fromRegexp .= 'i';
|
||||
}
|
||||
|
||||
if (\is_array($to) || $to instanceof \Closure) {
|
||||
if (!\is_callable($to)) {
|
||||
throw new \TypeError(sprintf('Argument 2 passed to "%s::replaceMatches()" must be callable, array given.', static::class));
|
||||
}
|
||||
|
||||
$replace = 'preg_replace_callback';
|
||||
$to = static function (array $m) use ($to): string {
|
||||
$to = $to($m);
|
||||
@@ -339,7 +321,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
$lastError = preg_last_error();
|
||||
|
||||
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
|
||||
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
|
||||
if ($lastError === $v && str_ends_with($k, '_ERROR')) {
|
||||
throw new RuntimeException('Matching failed with '.$k.'.');
|
||||
}
|
||||
}
|
||||
@@ -356,7 +338,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function reverse(): parent
|
||||
public function reverse(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = implode('', array_reverse(preg_split('/(\X)/u', $str->string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY)));
|
||||
@@ -364,7 +346,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function snake(): parent
|
||||
public function snake(): static
|
||||
{
|
||||
$str = $this->camel();
|
||||
$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');
|
||||
@@ -372,7 +354,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function title(bool $allWords = false): parent
|
||||
public function title(bool $allWords = false): static
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
@@ -385,7 +367,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function trim(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"): parent
|
||||
public function trim(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"): static
|
||||
{
|
||||
if (" \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}" !== $chars && !preg_match('//u', $chars)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 chars.');
|
||||
@@ -398,7 +380,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function trimEnd(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"): parent
|
||||
public function trimEnd(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"): static
|
||||
{
|
||||
if (" \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}" !== $chars && !preg_match('//u', $chars)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 chars.');
|
||||
@@ -411,7 +393,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function trimPrefix($prefix): parent
|
||||
public function trimPrefix($prefix): static
|
||||
{
|
||||
if (!$this->ignoreCase) {
|
||||
return parent::trimPrefix($prefix);
|
||||
@@ -431,7 +413,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function trimStart(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"): parent
|
||||
public function trimStart(string $chars = " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"): static
|
||||
{
|
||||
if (" \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}" !== $chars && !preg_match('//u', $chars)) {
|
||||
throw new InvalidArgumentException('Invalid UTF-8 chars.');
|
||||
@@ -444,7 +426,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function trimSuffix($suffix): parent
|
||||
public function trimSuffix($suffix): static
|
||||
{
|
||||
if (!$this->ignoreCase) {
|
||||
return parent::trimSuffix($suffix);
|
||||
@@ -464,15 +446,11 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function upper(): parent
|
||||
public function upper(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = mb_strtoupper($str->string, 'UTF-8');
|
||||
|
||||
if (\PHP_VERSION_ID < 70300) {
|
||||
$str->string = str_replace(self::UPPER_FROM, self::UPPER_TO, $str->string);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
@@ -481,7 +459,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
$width = 0;
|
||||
$s = str_replace(["\x00", "\x05", "\x07"], '', $this->string);
|
||||
|
||||
if (false !== strpos($s, "\r")) {
|
||||
if (str_contains($s, "\r")) {
|
||||
$s = str_replace(["\r\n", "\r"], "\n", $s);
|
||||
}
|
||||
|
||||
@@ -508,10 +486,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
private function pad(int $len, self $pad, int $type): parent
|
||||
private function pad(int $len, self $pad, int $type): static
|
||||
{
|
||||
$sLen = $this->length();
|
||||
|
||||
@@ -575,9 +550,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (null === self::$tableZero) {
|
||||
self::$tableZero = require __DIR__.'/Resources/data/wcswidth_table_zero.php';
|
||||
}
|
||||
self::$tableZero ??= require __DIR__.'/Resources/data/wcswidth_table_zero.php';
|
||||
|
||||
if ($codePoint >= self::$tableZero[0][0] && $codePoint <= self::$tableZero[$ubound = \count(self::$tableZero) - 1][1]) {
|
||||
$lbound = 0;
|
||||
@@ -594,9 +567,7 @@ abstract class AbstractUnicodeString extends AbstractString
|
||||
}
|
||||
}
|
||||
|
||||
if (null === self::$tableWide) {
|
||||
self::$tableWide = require __DIR__.'/Resources/data/wcswidth_table_wide.php';
|
||||
}
|
||||
self::$tableWide ??= require __DIR__.'/Resources/data/wcswidth_table_wide.php';
|
||||
|
||||
if ($codePoint >= self::$tableWide[0][0] && $codePoint <= self::$tableWide[$ubound = \count(self::$tableWide) - 1][1]) {
|
||||
$lbound = 0;
|
||||
|
Reference in New Issue
Block a user