@@ -18,8 +18,8 @@ |
||
18 | 18 | * @var array Characters to escape outside of a character class |
19 | 19 | */ |
20 | 20 | public $inLiteral = [ |
21 | - '$' => '\\$', '(' => '\\(', ')' => '\\)', '*' => '\\*', |
|
22 | - '+' => '\\+', '.' => '\\.', '?' => '\\?', '[' => '\\]', |
|
21 | + '$' => '\\$', '(' => '\\(', ')' => '\\)', '*' => '\\*', |
|
22 | + '+' => '\\+', '.' => '\\.', '?' => '\\?', '[' => '\\]', |
|
23 | 23 | '\\' => '\\\\', '^' => '\\^', '{' => '\\{', '|' => '\\|' |
24 | 24 | ]; |
25 | 25 |
@@ -9,51 +9,51 @@ |
||
9 | 9 | |
10 | 10 | class Escaper |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array Characters to escape in a character class |
|
14 | - */ |
|
15 | - public $inCharacterClass = ['-' => '\\-', '\\' => '\\\\', ']' => '\\]']; |
|
12 | + /** |
|
13 | + * @var array Characters to escape in a character class |
|
14 | + */ |
|
15 | + public $inCharacterClass = ['-' => '\\-', '\\' => '\\\\', ']' => '\\]']; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var array Characters to escape outside of a character class |
|
19 | - */ |
|
20 | - public $inLiteral = [ |
|
21 | - '$' => '\\$', '(' => '\\(', ')' => '\\)', '*' => '\\*', |
|
22 | - '+' => '\\+', '.' => '\\.', '?' => '\\?', '[' => '\\]', |
|
23 | - '\\' => '\\\\', '^' => '\\^', '{' => '\\{', '|' => '\\|' |
|
24 | - ]; |
|
17 | + /** |
|
18 | + * @var array Characters to escape outside of a character class |
|
19 | + */ |
|
20 | + public $inLiteral = [ |
|
21 | + '$' => '\\$', '(' => '\\(', ')' => '\\)', '*' => '\\*', |
|
22 | + '+' => '\\+', '.' => '\\.', '?' => '\\?', '[' => '\\]', |
|
23 | + '\\' => '\\\\', '^' => '\\^', '{' => '\\{', '|' => '\\|' |
|
24 | + ]; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @param string $delimiter Delimiter used in the final regexp |
|
28 | - */ |
|
29 | - public function __construct($delimiter = '/') |
|
30 | - { |
|
31 | - foreach (str_split($delimiter, 1) as $char) |
|
32 | - { |
|
33 | - $this->inCharacterClass[$char] = '\\' . $char; |
|
34 | - $this->inLiteral[$char] = '\\' . $char; |
|
35 | - } |
|
36 | - } |
|
26 | + /** |
|
27 | + * @param string $delimiter Delimiter used in the final regexp |
|
28 | + */ |
|
29 | + public function __construct($delimiter = '/') |
|
30 | + { |
|
31 | + foreach (str_split($delimiter, 1) as $char) |
|
32 | + { |
|
33 | + $this->inCharacterClass[$char] = '\\' . $char; |
|
34 | + $this->inLiteral[$char] = '\\' . $char; |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Escape given character to be used in a character class |
|
40 | - * |
|
41 | - * @param string $char Original character |
|
42 | - * @return string Escaped character |
|
43 | - */ |
|
44 | - public function escapeCharacterClass($char) |
|
45 | - { |
|
46 | - return (isset($this->inCharacterClass[$char])) ? $this->inCharacterClass[$char] : $char; |
|
47 | - } |
|
38 | + /** |
|
39 | + * Escape given character to be used in a character class |
|
40 | + * |
|
41 | + * @param string $char Original character |
|
42 | + * @return string Escaped character |
|
43 | + */ |
|
44 | + public function escapeCharacterClass($char) |
|
45 | + { |
|
46 | + return (isset($this->inCharacterClass[$char])) ? $this->inCharacterClass[$char] : $char; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Escape given character to be used outside of a character class |
|
51 | - * |
|
52 | - * @param string $char Original character |
|
53 | - * @return string Escaped character |
|
54 | - */ |
|
55 | - public function escapeLiteral($char) |
|
56 | - { |
|
57 | - return (isset($this->inLiteral[$char])) ? $this->inLiteral[$char] : $char; |
|
58 | - } |
|
49 | + /** |
|
50 | + * Escape given character to be used outside of a character class |
|
51 | + * |
|
52 | + * @param string $char Original character |
|
53 | + * @return string Escaped character |
|
54 | + */ |
|
55 | + public function escapeLiteral($char) |
|
56 | + { |
|
57 | + return (isset($this->inLiteral[$char])) ? $this->inLiteral[$char] : $char; |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -9,11 +9,11 @@ |
||
9 | 9 | |
10 | 10 | interface PassInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * Run this pass |
|
14 | - * |
|
15 | - * @param array[] $strings Original strings |
|
16 | - * @return array[] Modified strings |
|
17 | - */ |
|
18 | - public function run(array $strings); |
|
12 | + /** |
|
13 | + * Run this pass |
|
14 | + * |
|
15 | + * @param array[] $strings Original strings |
|
16 | + * @return array[] Modified strings |
|
17 | + */ |
|
18 | + public function run(array $strings); |
|
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -11,26 +11,26 @@ |
||
11 | 11 | |
12 | 12 | class Utf8ToSurrogates extends Utf8 |
13 | 13 | { |
14 | - /** |
|
15 | - * {@inheritdoc} |
|
16 | - */ |
|
17 | - protected function charsToCodepoints(array $chars) |
|
18 | - { |
|
19 | - $codepoints = []; |
|
20 | - foreach ($chars as $char) |
|
21 | - { |
|
22 | - $cp = $this->cp($char); |
|
23 | - if ($cp < 0x10000) |
|
24 | - { |
|
25 | - $codepoints[] = $cp; |
|
26 | - } |
|
27 | - else |
|
28 | - { |
|
29 | - $codepoints[] = 0xD7C0 + ($cp >> 10); |
|
30 | - $codepoints[] = 0xDC00 + ($cp & 0x3FF); |
|
31 | - } |
|
32 | - } |
|
14 | + /** |
|
15 | + * {@inheritdoc} |
|
16 | + */ |
|
17 | + protected function charsToCodepoints(array $chars) |
|
18 | + { |
|
19 | + $codepoints = []; |
|
20 | + foreach ($chars as $char) |
|
21 | + { |
|
22 | + $cp = $this->cp($char); |
|
23 | + if ($cp < 0x10000) |
|
24 | + { |
|
25 | + $codepoints[] = $cp; |
|
26 | + } |
|
27 | + else |
|
28 | + { |
|
29 | + $codepoints[] = 0xD7C0 + ($cp >> 10); |
|
30 | + $codepoints[] = 0xDC00 + ($cp & 0x3FF); |
|
31 | + } |
|
32 | + } |
|
33 | 33 | |
34 | - return $codepoints; |
|
35 | - } |
|
34 | + return $codepoints; |
|
35 | + } |
|
36 | 36 | } |
37 | 37 | \ No newline at end of file |
@@ -9,16 +9,16 @@ |
||
9 | 9 | |
10 | 10 | class Bytes implements InputInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - public function split($string) |
|
16 | - { |
|
17 | - if ($string === '') |
|
18 | - { |
|
19 | - return []; |
|
20 | - } |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + public function split($string) |
|
16 | + { |
|
17 | + if ($string === '') |
|
18 | + { |
|
19 | + return []; |
|
20 | + } |
|
21 | 21 | |
22 | - return array_map('ord', str_split($string, 1)); |
|
23 | - } |
|
22 | + return array_map('ord', str_split($string, 1)); |
|
23 | + } |
|
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -9,11 +9,11 @@ |
||
9 | 9 | |
10 | 10 | interface InputInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * Split given string into a list of values |
|
14 | - * |
|
15 | - * @param string $string |
|
16 | - * @return integer[] |
|
17 | - */ |
|
18 | - public function split($string); |
|
12 | + /** |
|
13 | + * Split given string into a list of values |
|
14 | + * |
|
15 | + * @param string $string |
|
16 | + * @return integer[] |
|
17 | + */ |
|
18 | + public function split($string); |
|
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -11,35 +11,35 @@ |
||
11 | 11 | |
12 | 12 | class Runner |
13 | 13 | { |
14 | - /** |
|
15 | - * @var PassInterface[] |
|
16 | - */ |
|
17 | - protected $passes = []; |
|
14 | + /** |
|
15 | + * @var PassInterface[] |
|
16 | + */ |
|
17 | + protected $passes = []; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Add a pass to the list |
|
21 | - * |
|
22 | - * @param PassInterface $pass |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - public function addPass(PassInterface $pass) |
|
26 | - { |
|
27 | - $this->passes[] = $pass; |
|
28 | - } |
|
19 | + /** |
|
20 | + * Add a pass to the list |
|
21 | + * |
|
22 | + * @param PassInterface $pass |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + public function addPass(PassInterface $pass) |
|
26 | + { |
|
27 | + $this->passes[] = $pass; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Run all passes on the list of strings |
|
32 | - * |
|
33 | - * @param array[] $strings |
|
34 | - * @return array[] |
|
35 | - */ |
|
36 | - public function run(array $strings) |
|
37 | - { |
|
38 | - foreach ($this->passes as $pass) |
|
39 | - { |
|
40 | - $strings = $pass->run($strings); |
|
41 | - } |
|
30 | + /** |
|
31 | + * Run all passes on the list of strings |
|
32 | + * |
|
33 | + * @param array[] $strings |
|
34 | + * @return array[] |
|
35 | + */ |
|
36 | + public function run(array $strings) |
|
37 | + { |
|
38 | + foreach ($this->passes as $pass) |
|
39 | + { |
|
40 | + $strings = $pass->run($strings); |
|
41 | + } |
|
42 | 42 | |
43 | - return $strings; |
|
44 | - } |
|
43 | + return $strings; |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | \ No newline at end of file |
@@ -9,11 +9,11 @@ |
||
9 | 9 | |
10 | 10 | interface OutputInterface |
11 | 11 | { |
12 | - /** |
|
13 | - * Serialize a value into a character |
|
14 | - * |
|
15 | - * @param integer $value |
|
16 | - * @return string |
|
17 | - */ |
|
18 | - public function output($value); |
|
12 | + /** |
|
13 | + * Serialize a value into a character |
|
14 | + * |
|
15 | + * @param integer $value |
|
16 | + * @return string |
|
17 | + */ |
|
18 | + public function output($value); |
|
19 | 19 | } |
20 | 20 | \ No newline at end of file |
@@ -9,53 +9,53 @@ |
||
9 | 9 | |
10 | 10 | abstract class PrintableAscii extends BaseImplementation |
11 | 11 | { |
12 | - /** |
|
13 | - * {@inheritdoc} |
|
14 | - */ |
|
15 | - protected function outputValidValue($value) |
|
16 | - { |
|
17 | - if ($value < 32) |
|
18 | - { |
|
19 | - return $this->escapeControlCode($value); |
|
20 | - } |
|
21 | - |
|
22 | - if ($value < 127) |
|
23 | - { |
|
24 | - return chr($value); |
|
25 | - } |
|
26 | - |
|
27 | - 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 | - protected function escapeAscii($cp) |
|
37 | - { |
|
38 | - return '\\x' . sprintf('%02X', $cp); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Escape given control code |
|
43 | - * |
|
44 | - * @param integer $cp |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - protected function escapeControlCode($cp) |
|
48 | - { |
|
49 | - $table = [9 => '\\t', 10 => '\\n', 13 => '\\r']; |
|
50 | - |
|
51 | - return (isset($table[$cp])) ? $table[$cp] : $this->escapeAscii($cp); |
|
52 | - } |
|
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); |
|
12 | + /** |
|
13 | + * {@inheritdoc} |
|
14 | + */ |
|
15 | + protected function outputValidValue($value) |
|
16 | + { |
|
17 | + if ($value < 32) |
|
18 | + { |
|
19 | + return $this->escapeControlCode($value); |
|
20 | + } |
|
21 | + |
|
22 | + if ($value < 127) |
|
23 | + { |
|
24 | + return chr($value); |
|
25 | + } |
|
26 | + |
|
27 | + 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 | + protected function escapeAscii($cp) |
|
37 | + { |
|
38 | + return '\\x' . sprintf('%02X', $cp); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Escape given control code |
|
43 | + * |
|
44 | + * @param integer $cp |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + protected function escapeControlCode($cp) |
|
48 | + { |
|
49 | + $table = [9 => '\\t', 10 => '\\n', 13 => '\\r']; |
|
50 | + |
|
51 | + return (isset($table[$cp])) ? $table[$cp] : $this->escapeAscii($cp); |
|
52 | + } |
|
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 | 61 | } |
62 | 62 | \ No newline at end of file |
@@ -9,31 +9,31 @@ |
||
9 | 9 | |
10 | 10 | class Utf8 extends BaseImplementation |
11 | 11 | { |
12 | - /** {@inheritdoc} */ |
|
13 | - protected $maxValue = 0x10FFFF; |
|
12 | + /** {@inheritdoc} */ |
|
13 | + protected $maxValue = 0x10FFFF; |
|
14 | 14 | |
15 | - /** |
|
16 | - * {@inheritdoc} |
|
17 | - */ |
|
18 | - protected function outputValidValue($value) |
|
19 | - { |
|
20 | - if ($value < 0x80) |
|
21 | - { |
|
22 | - return chr($value); |
|
23 | - } |
|
24 | - if ($value < 0x800) |
|
25 | - { |
|
26 | - return chr(0xC0 | ($value >> 6)) . chr(0x80 | ($value & 0x3F)); |
|
27 | - } |
|
28 | - if ($value < 0x10000) |
|
29 | - { |
|
30 | - return chr(0xE0 | ($value >> 12)) |
|
31 | - . chr(0x80 | (($value >> 6) & 0x3F)) |
|
32 | - . chr(0x80 | ($value & 0x3F)); |
|
33 | - } |
|
34 | - return chr(0xF0 | ($value >> 18)) |
|
35 | - . chr(0x80 | (($value >> 12) & 0x3F)) |
|
36 | - . chr(0x80 | (($value >> 6) & 0x3F)) |
|
37 | - . chr(0x80 | ($value & 0x3F)); |
|
38 | - } |
|
15 | + /** |
|
16 | + * {@inheritdoc} |
|
17 | + */ |
|
18 | + protected function outputValidValue($value) |
|
19 | + { |
|
20 | + if ($value < 0x80) |
|
21 | + { |
|
22 | + return chr($value); |
|
23 | + } |
|
24 | + if ($value < 0x800) |
|
25 | + { |
|
26 | + return chr(0xC0 | ($value >> 6)) . chr(0x80 | ($value & 0x3F)); |
|
27 | + } |
|
28 | + if ($value < 0x10000) |
|
29 | + { |
|
30 | + return chr(0xE0 | ($value >> 12)) |
|
31 | + . chr(0x80 | (($value >> 6) & 0x3F)) |
|
32 | + . chr(0x80 | ($value & 0x3F)); |
|
33 | + } |
|
34 | + return chr(0xF0 | ($value >> 18)) |
|
35 | + . chr(0x80 | (($value >> 12) & 0x3F)) |
|
36 | + . chr(0x80 | (($value >> 6) & 0x3F)) |
|
37 | + . chr(0x80 | ($value & 0x3F)); |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | \ No newline at end of file |