includes/json2.php
changeset 880 218b6d4de908
parent 334 c72b545f1304
child 890 b624c55ab771
equal deleted inserted replaced
879:9788f2b7e08a 880:218b6d4de908
   771                                 $result .= chr(9);
   771                                 $result .= chr(9);
   772                                 break;
   772                                 break;
   773                             case '\'' :
   773                             case '\'' :
   774                                 $result .= '\'';
   774                                 $result .= '\'';
   775                                 break;
   775                                 break;
       
   776                             case 'u':
       
   777                               $result .= self::decode_unicode_byte(substr($str, $i + 1, 4));
       
   778                               break;
   776                             default:
   779                             default:
   777                                 throw new Zend_Json_Exception("Illegal escape "
   780                                 throw new Zend_Json_Exception("Illegal escape "
   778                                     .  "sequence '" . $chr . "'");
   781                                     .  "sequence '" . $chr . "'");
   779                             }
   782                             }
   780                     } elseif ($chr == '"') {
   783                     } elseif ($chr == '"') {
   901         } else {
   904         } else {
   902             throw new Zend_Json_Exception("Illegal Token at pos $i: $chr\nContext:\n--------------------------------------------------" . substr($str, $i) . "\n--------------------------------------------------");
   905             throw new Zend_Json_Exception("Illegal Token at pos $i: $chr\nContext:\n--------------------------------------------------" . substr($str, $i) . "\n--------------------------------------------------");
   903         }
   906         }
   904 
   907 
   905         return($this->_token);
   908         return($this->_token);
       
   909     }
       
   910     
       
   911     /**
       
   912      * Handle a Unicode byte; local to Enano.
       
   913      * @param string 4 character byte sequence
       
   914      * @return string
       
   915      */
       
   916     
       
   917     protected function decode_unicode_byte($byte)
       
   918     {
       
   919       if ( strlen($byte) != 4 )
       
   920         throw new Zend_Json_Exception("Invalid Unicode sequence \\u$byte");
       
   921         
       
   922       $value = hexdec($byte);
       
   923 
       
   924       if ($value < 0x0080)
       
   925       {
       
   926         // 1 byte: 0xxxxxxx
       
   927         $character = chr($value);
       
   928       }
       
   929       else if ($value < 0x0800)
       
   930       {
       
   931         // 2 bytes: 110xxxxx 10xxxxxx
       
   932         $character =
       
   933             chr((($value & 0x07c0) >> 6) | 0xc0)
       
   934           . chr(($value & 0x3f) | 0x80);
       
   935       }
       
   936       else
       
   937       {
       
   938         // 3 bytes: 1110xxxx 10xxxxxx 10xxxxxx
       
   939         $character =
       
   940             chr((($value & 0xf000) >> 12) | 0xe0)
       
   941           . chr((($value & 0x0fc0) >> 6) | 0x80)
       
   942           . chr(($value & 0x3f) | 0x80);
       
   943       }
   906     }
   944     }
   907 }
   945 }
   908 
   946 
   909 /**
   947 /**
   910  * Zend Framework
   948  * Zend Framework