Total Complexity | 6 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 91.67% |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class StringUtil |
||
6 | { |
||
7 | const BOM_UTF8 = "\xEF\xBB\xBF"; |
||
8 | const BOM_UTF16_BE = "\xFE\xFF"; |
||
9 | const BOM_UTF16_LE = "\xFF\xFE"; |
||
10 | const BOM_UTF32_BE = "\x00\x00\xFE\xFF"; |
||
11 | const BOM_UTF32_LE = "\xFF\xFE\x00\x00"; |
||
12 | |||
13 | /** |
||
14 | * Returns whether the given string starts with the given Byte Order Mark. |
||
15 | */ |
||
16 | 6 | public static function hasBom(string $input, string $bom): bool |
|
17 | { |
||
18 | 6 | return \strpos($input, $bom) === 0; |
|
19 | } |
||
20 | |||
21 | /** |
||
22 | * Strips a Byte Order Mark from the beginning of a string if it is present. |
||
23 | */ |
||
24 | 5 | public static function stripBom(string $input, string $bom): string |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * Escapes the enclosure character recursively. |
||
35 | * RFC-4180 states the enclosure character (usually double quotes) should be |
||
36 | * escaped by itself, so " becomes "". |
||
37 | * |
||
38 | * @see https://tools.ietf.org/html/rfc4180#section-2 |
||
39 | */ |
||
40 | 2 | public static function escapeEnclosure(array $data, string $enclosure): array |
|
53 |