1 | <?php |
||
10 | abstract class PrintableAscii extends BaseImplementation |
||
11 | { |
||
12 | /** |
||
13 | * {@inheritdoc} |
||
14 | */ |
||
15 | 17 | protected function outputValidValue($value) |
|
16 | { |
||
17 | 17 | if ($value < 32) |
|
18 | { |
||
19 | 6 | return $this->escapeControlCode($value); |
|
20 | } |
||
21 | |||
22 | 11 | if ($value < 127) |
|
23 | { |
||
24 | 6 | return chr($value); |
|
25 | } |
||
26 | |||
27 | 5 | return ($value > 255) ? $this->escapeUnicode($value) : $this->escapeAscii($value); |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * Escape given ASCII codepoint |
||
32 | * |
||
33 | * @param integer $cp |
||
34 | * @return string |
||
35 | */ |
||
36 | 2 | protected function escapeAscii($cp) |
|
40 | |||
41 | /** |
||
42 | * Escape given control code |
||
43 | * |
||
44 | * @param integer $cp |
||
45 | * @return string |
||
46 | */ |
||
47 | 6 | protected function escapeControlCode($cp) |
|
53 | |||
54 | /** |
||
55 | * Output the representation of a unicode character |
||
56 | * |
||
57 | * @param integer $cp Unicode codepoint |
||
58 | * @return string |
||
59 | */ |
||
60 | abstract protected function escapeUnicode($cp); |
||
61 | } |