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