__decode() 공개 메소드

public __decode ( &$encode, &$pos, &$slen, &$stdClass )
예제 #1
0
 function __decode(&$encode, &$pos, &$slen, &$stdClass)
 {
     switch ($encode[$pos]) {
         case 't':
             $result = true;
             $pos += 4;
             break;
         case 'f':
             $result = false;
             $pos += 5;
             break;
         case 'n':
             $result = null;
             $pos += 4;
             break;
         case '[':
             $result = array();
             ++$pos;
             while ($encode[$pos] !== ']') {
                 array_push($result, FastJSON::__decode($encode, $pos, $slen, $stdClass));
                 if ($encode[$pos] === ',') {
                     ++$pos;
                 }
             }
             ++$pos;
             break;
         case '{':
             $result = $stdClass ? new stdClass() : array();
             ++$pos;
             while ($encode[$pos] !== '}') {
                 $tmp = FastJSON::__decodeString($encode, $pos);
                 ++$pos;
                 if ($stdClass) {
                     $result->{$tmp} = FastJSON::__decode($encode, $pos, $slen, $stdClass);
                 } else {
                     $result[$tmp] = FastJSON::__decode($encode, $pos, $slen, $stdClass);
                 }
                 if ($encode[$pos] === ',') {
                     ++$pos;
                 }
             }
             ++$pos;
             break;
         case '"':
             switch ($encode[++$pos]) {
                 case '"':
                     $result = "";
                     break;
                 default:
                     $result = FastJSON::__decodeString($encode, $pos);
                     break;
             }
             ++$pos;
             break;
         default:
             $tmp = '';
             preg_replace('/^(\\-)?([0-9]+)(\\.[0-9]+)?([eE]\\+[0-9]+)?/e', '$tmp = "\\1\\2\\3\\4"', substr($encode, $pos));
             if ($tmp !== '') {
                 $pos += strlen($tmp);
                 $nint = intval($tmp);
                 $nfloat = floatval($tmp);
                 $result = $nfloat == $nint ? $nint : $nfloat;
             }
             break;
     }
     return $result;
 }