/** * 引数の文字列から UTF-8 として不適切なシーケンスを除去します. * * @param string $var 文字列 * @return string 不正なシーケンスを除去した結果 */ private static function cleanString($var) { // @codeCoverageIgnoreStart static $utf8Codec = null; if ($utf8Codec === null) { $utf8Codec = new Utf8Codec(); } // @codeCoverageIgnoreEnd $str = Values::stringValue($var); return $utf8Codec->encode($utf8Codec->decode($str)); }
/** * 指定された Unicode 符号点を JSON 文字に変換します. * * @param int $num Unicode 符号点 * @return string 指定された Unicode 符号点に対応する文字列 * @ignore */ public function encodeCodePoint($num) { // @codeCoverageIgnoreStart static $hexList = array(0x3c => self::HEX_TAG, 0x3e => self::HEX_TAG, 0x26 => self::HEX_AMP, 0x27 => self::HEX_APOS, 0x22 => self::HEX_QUOT); static $encodeList = array(0x22 => "\\\"", 0x5c => "\\\\", 0x8 => "\\b", 0xc => "\\f", 0xa => "\\n", 0xd => "\\r", 0x9 => "\\t"); // @codeCoverageIgnoreEnd if (array_key_exists($num, $hexList) && $this->getEncodeOption($hexList[$num])) { return "\\u00" . strtoupper(dechex($num)); } if (array_key_exists($num, $encodeList)) { return $encodeList[$num]; } if ($num === 0x2f) { return $this->getEncodeOption(self::UNESCAPED_SLASHES) ? "/" : "\\/"; } if (0x20 <= $num && $num < 0x80) { return chr($num); } if (0x80 <= $num && $this->getEncodeOption(self::UNESCAPED_UNICODE)) { return $this->utf8Codec->encode($num); } return "\\u" . str_pad(dechex($num), 4, "0", STR_PAD_LEFT); }