| Total Complexity | 10 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 10 | abstract class PrintableAscii extends BaseImplementation |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var string 'x' for lowercase hexadecimal symbols, 'X' for uppercase |
||
| 14 | */ |
||
| 15 | protected $hexCase; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * {@inheritdoc} |
||
| 19 | */ |
||
| 20 | 34 | public function __construct(array $options = []) |
|
| 23 | 34 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * Escape given ASCII codepoint |
||
| 27 | * |
||
| 28 | * @param integer $cp |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | 6 | protected function escapeAscii(int $cp): string |
|
| 32 | { |
||
| 33 | 6 | return '\\x' . sprintf('%02' . $this->hexCase, $cp); |
|
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Escape given control code |
||
| 38 | * |
||
| 39 | * @param integer $cp |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | 6 | protected function escapeControlCode(int $cp): string |
|
| 43 | { |
||
| 44 | 6 | $table = [9 => '\\t', 10 => '\\n', 13 => '\\r']; |
|
| 45 | |||
| 46 | 6 | return (isset($table[$cp])) ? $table[$cp] : $this->escapeAscii($cp); |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Output the representation of a unicode character |
||
| 51 | * |
||
| 52 | * @param integer $cp Unicode codepoint |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | abstract protected function escapeUnicode(int $cp): string; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | 32 | protected function outputValidValue(int $value): string |
|
| 73 | } |
||
| 74 | } |