/** * 文字 %x20, %x09, %x0A, %x0D を読み飛ばします. * * @param Context $context */ public function handle(Context $context) { static $wsList = array("\r", "\n", "\r\n", "\t", " "); while ($context->hasNext()) { $current = $context->current(); if (!in_array($current, $wsList)) { break; } $context->next(); } }
/** * 二重引用符で囲まれた JSON 文字列を解析し, 対応する文字列に変換します. * * @param Context $context 処理対象の Context オブジェクト */ public function handle(Context $context) { $quot = $context->current(); if ($quot !== '"') { $context->throwException("A string must be quoted by '\"'"); } $context->next(); $value = ""; $escaped = false; while ($context->hasNext()) { if ($escaped) { $value .= $this->decodeEscapedChar($context); $escaped = false; continue; } $this->validateCodePoint($context); $current = $context->current(); $context->next(); switch ($current) { case '"': $this->result = $value; return; case "\\": $escaped = true; break; default: $value .= $current; break; } } $context->throwException("End of quotation mark not found"); }