| 1 | <?php |
||
| 13 | class XLSX implements EscaperInterface |
||
| 14 | { |
||
| 15 | use Singleton; |
||
| 16 | |||
| 17 | /** @var string[] Control characters to be escaped */ |
||
| 18 | protected $controlCharactersEscapingMap; |
||
| 19 | 330 | ||
| 20 | /** |
||
| 21 | 330 | * Initializes the singleton instance |
|
| 22 | 330 | */ |
|
| 23 | protected function init() |
||
| 27 | |||
| 28 | /** |
||
|
1 ignored issue
–
show
|
|||
| 29 | * Escapes the given string to make it compatible with XLSX |
||
| 30 | 87 | * |
|
| 31 | * @param string $string The string to escape |
||
| 32 | 87 | * @return string The escaped string |
|
| 33 | 87 | */ |
|
| 34 | public function escape($string) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Unescapes the given string to make it compatible with XLSX |
||
| 44 | 129 | * |
|
| 45 | * @param string $string The string to unescape |
||
| 46 | 129 | * @return string The unescaped string |
|
| 47 | 129 | */ |
|
| 48 | public function unescape($string) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Builds the map containing control characters to be escaped |
||
| 58 | * mapped to their escaped values. |
||
| 59 | * "\t", "\r" and "\n" don't need to be escaped. |
||
| 60 | * |
||
| 61 | * NOTE: the logic has been adapted from the XlsxWriter library (BSD License) |
||
| 62 | 330 | * @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 |
|
| 63 | * |
||
| 64 | 330 | * @return string[] |
|
| 65 | 330 | */ |
|
| 66 | protected function getControlCharactersEscapingMap() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Converts PHP control characters from the given string to OpenXML escaped control characters |
||
| 85 | * |
||
| 86 | * Excel escapes control characters with _xHHHH_ and also escapes any |
||
| 87 | * literal strings of that type by encoding the leading underscore. |
||
| 88 | * So "\0" -> _x0000_ and "_x0000_" -> _x005F_x0000_. |
||
| 89 | * |
||
| 90 | * NOTE: the logic has been adapted from the XlsxWriter library (BSD License) |
||
| 91 | * @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 |
||
| 92 | 87 | * |
|
| 93 | * @param string $string String to escape |
||
| 94 | 87 | * @return string |
|
| 95 | 87 | */ |
|
| 96 | protected function escapeControlCharacters($string) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Escapes the escape character: "_x0000_" -> "_x005F_x0000_" |
||
| 104 | 87 | * |
|
| 105 | * @param string $string String to escape |
||
| 106 | 87 | * @return string The escaped string |
|
| 107 | */ |
||
| 108 | protected function escapeEscapeCharacter($string) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Converts OpenXML escaped control characters from the given string to PHP control characters |
||
| 115 | * |
||
| 116 | * Excel escapes control characters with _xHHHH_ and also escapes any |
||
| 117 | * literal strings of that type by encoding the leading underscore. |
||
| 118 | * So "_x0000_" -> "\0" and "_x005F_x0000_" -> "_x0000_" |
||
| 119 | * |
||
| 120 | * NOTE: the logic has been adapted from the XlsxWriter library (BSD License) |
||
| 121 | * @link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89 |
||
| 122 | 129 | * |
|
| 123 | * @param string $string String to unescape |
||
| 124 | 129 | * @return string |
|
| 125 | 129 | */ |
|
| 126 | protected function unescapeControlCharacters($string) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Unecapes the escape character: "_x005F_x0000_" => "_x0000_" |
||
| 139 | 129 | * |
|
| 140 | * @param string $string String to unescape |
||
| 141 | 129 | * @return string The unescaped string |
|
| 142 | */ |
||
| 143 | protected function unescapeEscapeCharacter($string) |
||
| 147 | } |
||
| 148 |