/** * "\" で始まる文字列を対応する文字に変換します. * * @param Context $context * @return string */ private function decodeEscapedChar(Context $context) { // @codeCoverageIgnoreStart static $specials = null; if ($specials === null) { $specials = array("\\" => "\\", '"' => '"', "/" => "/", "b" => chr(0x8), "f" => chr(0xc), "n" => "\n", "r" => "\r", "t" => "\t"); } // @codeCoverageIgnoreEnd $current = $context->current(); if (array_key_exists($current, $specials)) { $context->next(); return $specials[$current]; } // decode \uXXXX if ($current !== "u") { $context->throwException("Invalid escape sequence ('\\{$current}')"); } $context->next(); $hex = $context->getSequence(4); if (!preg_match("/^[0-9A-Fa-f]{4}\$/", $hex)) { $context->throwException("Invalid hexadecimal sequence (Expected: \\uXXXX)"); } $context->skip(4); return $context->encodeCodepoint(hexdec($hex)); }