/** * Sets the character code. It can be 0, 1 or 2 digits that represents * the octal number that identifies the character * * @param string $char Character to match * * @return OctalChar * * @throws \REBuilder\Exception\Generic * * @link http://php.net/manual/en/regexp.reference.escape.php */ public function setChar($char) { if (!preg_match("#^(?:0[0-7]{1,2}|[0-7]{2,3})\$#", $char)) { throw new \REBuilder\Exception\Generic("Invalid octal character '{$char}'"); } return parent::setChar($char); }
/** * Sets the character code . It can be 0, 1 or 2 hexadecimal digits * that represent a character code * * @param string $char Character to match * * @return HexChar * * @throws \REBuilder\Exception\Generic * * @link http://php.net/manual/en/regexp.reference.escape.php */ public function setChar($char) { if ($char !== "" && !\REBuilder\Parser\Rules::validateHexString($char)) { throw new \REBuilder\Exception\Generic("Invalid hexadecimal sequence '{$char}'"); } elseif (strlen($char) > 2) { throw new \REBuilder\Exception\Generic("Hexadecimal character can match a maximum of 2 digits"); } return parent::setChar($char); }
/** * Returns the string representation of the class * * @return string */ public function render() { return "\\c" . parent::render() . $this->_renderRepetition(); }
/** * Returns the string representation of the class * * @return string */ public function render() { $char = parent::render(); $needsGroup = strlen($this->getChar()) > 1 && $this->getRepetition(); return ($needsGroup ? "(?:{$char})" : $char) . $this->_renderRepetition(); }