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