tablepress
/
libraries
/
vendor
/
PhpSpreadsheet
/
Style
/
NumberFormat
/
Wizard
/
DateTimeWizard.php
DateTimeWizard.php in TablePress – Tables in WordPress made easy 3.4, at libraries/vendor/PhpSpreadsheet/Style/NumberFormat/Wizard/DateTimeWizard.php
| 1 | <?php |
| 2 | |
| 3 | namespace TablePress\PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard; |
| 4 | |
| 5 | use Stringable; |
| 6 | |
| 7 | abstract class DateTimeWizard implements Wizard |
| 8 | { |
| 9 | protected const NO_ESCAPING_NEEDED = "$+-/():!^&'~{}<>= "; |
| 10 | |
| 11 | /** |
| 12 | * @param array<?string> $separators |
| 13 | * |
| 14 | * @return array<?string> |
| 15 | */ |
| 16 | protected function padSeparatorArray(array $separators, int $count): array |
| 17 | { |
| 18 | $lastSeparator = (string) array_pop($separators); |
| 19 | |
| 20 | return $separators + array_fill(0, $count, $lastSeparator); |
| 21 | } |
| 22 | |
| 23 | protected function escapeSingleCharacter(string $value): string |
| 24 | { |
| 25 | if (str_contains(self::NO_ESCAPING_NEEDED, $value)) { |
| 26 | return $value; |
| 27 | } |
| 28 | |
| 29 | return "\\{$value}"; |
| 30 | } |
| 31 | |
| 32 | protected function wrapLiteral(string $value): string |
| 33 | { |
| 34 | if (mb_strlen($value, 'UTF-8') === 1) { |
| 35 | return $this->escapeSingleCharacter($value); |
| 36 | } |
| 37 | |
| 38 | // Wrap any other string literals in quotes, so that they're clearly defined as string literals |
| 39 | return '"' . str_replace('"', '""', $value) . '"'; |
| 40 | } |
| 41 | |
| 42 | protected function intersperse(string $formatBlock, ?string $separator): string |
| 43 | { |
| 44 | return "{$formatBlock}{$separator}"; |
| 45 | } |
| 46 | |
| 47 | public function __toString(): string |
| 48 | { |
| 49 | return $this->format(); |
| 50 | } |
| 51 | } |
| 52 |