for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @package s9e\RegexpBuilder
* @copyright Copyright (c) 2016 The s9e Authors
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
namespace s9e\RegexpBuilder\Output;
abstract class PrintableAscii extends BaseImplementation
{
* {@inheritdoc}
public function __construct(array $options = [])
$this->hexCase = (isset($options['case']) && $options['case'] === 'lower') ? 'x' : 'X';
hexCase
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
* Escape given ASCII codepoint
*
* @param integer $cp
* @return string
protected function escapeAscii($cp)
return '\\x' . sprintf('%02' . $this->hexCase, $cp);
* Escape given control code
protected function escapeControlCode($cp)
$table = [9 => '\\t', 10 => '\\n', 13 => '\\r'];
return (isset($table[$cp])) ? $table[$cp] : $this->escapeAscii($cp);
* Output the representation of a unicode character
* @param integer $cp Unicode codepoint
abstract protected function escapeUnicode($cp);
protected function outputValidValue($value)
if ($value < 32)
return $this->escapeControlCode($value);
if ($value < 127)
return chr($value);
return ($value > 255) ? $this->escapeUnicode($value) : $this->escapeAscii($value);
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: