|
8 | 8 | * License: GNU/GPLv2
|
9 | 9 | * @see LICENSE.txt
|
10 | 10 | *
|
11 |
| - * This file: The loader (last modified: 2022.06.19). |
| 11 | + * This file: The loader (last modified: 2022.09.22). |
12 | 12 | */
|
13 | 13 |
|
14 | 14 | namespace phpMussel\Core;
|
@@ -467,17 +467,25 @@ public function readFile(string $File): string
|
467 | 467 | */
|
468 | 468 | public function readBytes(string $In, int $Mode = 0)
|
469 | 469 | {
|
470 |
| - if (preg_match('/[KMGT][oB]$/i', $In)) { |
471 |
| - $Unit = substr($In, -2, 1); |
472 |
| - } elseif (preg_match('/[KMGToB]$/i', $In)) { |
473 |
| - $Unit = substr($In, -1); |
| 470 | + $Unit = ''; |
| 471 | + if (preg_match('/([KkMmGgTtPpOoBb]|К|к|М|м|Г|г|Т|т|П|п|K|k|M|m|G|g|T|t|P|p|Б|б|B|b)([OoBb]|Б|б|B|b)?$/', $In, $Matches)) { |
| 472 | + if (preg_match('/^([Kk]|К|к)$/', $Matches[1])) { |
| 473 | + $Unit = 'K'; |
| 474 | + } elseif (preg_match('/^([Mm]|М|м)$/', $Matches[1])) { |
| 475 | + $Unit = 'M'; |
| 476 | + } elseif (preg_match('/^([Gg]|Г|г)$/', $Matches[1])) { |
| 477 | + $Unit = 'G'; |
| 478 | + } elseif (preg_match('/^([Tt]|Т|т)$/', $Matches[1])) { |
| 479 | + $Unit = 'T'; |
| 480 | + } elseif (preg_match('/^([Pp]|П|п)$/', $Matches[1])) { |
| 481 | + $Unit = 'P'; |
| 482 | + } |
474 | 483 | }
|
475 |
| - $Unit = isset($Unit) ? strtoupper($Unit) : 'K'; |
476 | 484 | $In = (float)$In;
|
477 | 485 | if ($Mode === 1) {
|
478 |
| - return $Unit === 'B' || $Unit === 'o' ? $In . 'B' : $In . $Unit . 'B'; |
| 486 | + return $Unit === '' ? $In . 'B' : $In . $Unit . 'B'; |
479 | 487 | }
|
480 |
| - $Multiply = ['K' => 1024, 'M' => 1048576, 'G' => 1073741824, 'T' => 1099511627776]; |
| 488 | + $Multiply = ['K' => 1024, 'M' => 1048576, 'G' => 1073741824, 'T' => 1099511627776, 'P' => 1125899906842620]; |
481 | 489 | if (isset($Multiply[$Unit])) {
|
482 | 490 | $In *= $Multiply[$Unit];
|
483 | 491 | }
|
|
0 commit comments