🔧
This commit is contained in:
114
vendor/symfony/polyfill-php83/Php83.php
vendored
114
vendor/symfony/polyfill-php83/Php83.php
vendored
@@ -13,6 +13,7 @@ namespace Symfony\Polyfill\Php83;
|
||||
|
||||
/**
|
||||
* @author Ion Bazan <ion.bazan@gmail.com>
|
||||
* @author Pierre Ambroise <pierre27.ambroise@gmail.com>
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
@@ -39,7 +40,7 @@ final class Php83
|
||||
return \JSON_ERROR_NONE === json_last_error();
|
||||
}
|
||||
|
||||
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, string $encoding = null): string
|
||||
public static function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = \STR_PAD_RIGHT, ?string $encoding = null): string
|
||||
{
|
||||
if (!\in_array($pad_type, [\STR_PAD_RIGHT, \STR_PAD_LEFT, \STR_PAD_BOTH], true)) {
|
||||
throw new \ValueError('mb_str_pad(): Argument #4 ($pad_type) must be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH');
|
||||
@@ -82,4 +83,115 @@ final class Php83
|
||||
return mb_substr(str_repeat($pad_string, $leftPaddingLength), 0, $leftPaddingLength, $encoding).$string.mb_substr(str_repeat($pad_string, $rightPaddingLength), 0, $rightPaddingLength, $encoding);
|
||||
}
|
||||
}
|
||||
|
||||
public static function str_increment(string $string): string
|
||||
{
|
||||
if ('' === $string) {
|
||||
throw new \ValueError('str_increment(): Argument #1 ($string) cannot be empty');
|
||||
}
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9]+$/', $string)) {
|
||||
throw new \ValueError('str_increment(): Argument #1 ($string) must be composed only of alphanumeric ASCII characters');
|
||||
}
|
||||
|
||||
if (is_numeric($string)) {
|
||||
$offset = stripos($string, 'e');
|
||||
if (false !== $offset) {
|
||||
$char = $string[$offset];
|
||||
++$char;
|
||||
$string[$offset] = $char;
|
||||
++$string;
|
||||
|
||||
switch ($string[$offset]) {
|
||||
case 'f':
|
||||
$string[$offset] = 'e';
|
||||
break;
|
||||
case 'F':
|
||||
$string[$offset] = 'E';
|
||||
break;
|
||||
case 'g':
|
||||
$string[$offset] = 'f';
|
||||
break;
|
||||
case 'G':
|
||||
$string[$offset] = 'F';
|
||||
break;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
return ++$string;
|
||||
}
|
||||
|
||||
public static function str_decrement(string $string): string
|
||||
{
|
||||
if ('' === $string) {
|
||||
throw new \ValueError('str_decrement(): Argument #1 ($string) cannot be empty');
|
||||
}
|
||||
|
||||
if (!preg_match('/^[a-zA-Z0-9]+$/', $string)) {
|
||||
throw new \ValueError('str_decrement(): Argument #1 ($string) must be composed only of alphanumeric ASCII characters');
|
||||
}
|
||||
|
||||
if (preg_match('/\A(?:0[aA0]?|[aA])\z/', $string)) {
|
||||
throw new \ValueError(sprintf('str_decrement(): Argument #1 ($string) "%s" is out of decrement range', $string));
|
||||
}
|
||||
|
||||
if (!\in_array(substr($string, -1), ['A', 'a', '0'], true)) {
|
||||
return implode('', \array_slice(str_split($string), 0, -1)).\chr(\ord(substr($string, -1)) - 1);
|
||||
}
|
||||
|
||||
$carry = '';
|
||||
$decremented = '';
|
||||
|
||||
for ($i = \strlen($string) - 1; $i >= 0; --$i) {
|
||||
$char = $string[$i];
|
||||
|
||||
switch ($char) {
|
||||
case 'A':
|
||||
if ('' !== $carry) {
|
||||
$decremented = $carry.$decremented;
|
||||
$carry = '';
|
||||
}
|
||||
$carry = 'Z';
|
||||
|
||||
break;
|
||||
case 'a':
|
||||
if ('' !== $carry) {
|
||||
$decremented = $carry.$decremented;
|
||||
$carry = '';
|
||||
}
|
||||
$carry = 'z';
|
||||
|
||||
break;
|
||||
case '0':
|
||||
if ('' !== $carry) {
|
||||
$decremented = $carry.$decremented;
|
||||
$carry = '';
|
||||
}
|
||||
$carry = '9';
|
||||
|
||||
break;
|
||||
case '1':
|
||||
if ('' !== $carry) {
|
||||
$decremented = $carry.$decremented;
|
||||
$carry = '';
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
if ('' !== $carry) {
|
||||
$decremented = $carry.$decremented;
|
||||
$carry = '';
|
||||
}
|
||||
|
||||
if (!\in_array($char, ['A', 'a', '0'], true)) {
|
||||
$decremented = \chr(\ord($char) - 1).$decremented;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $decremented;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user