"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "framework/web/helpers/CJSON.php" between
yii-1.1.21.733ac5.tar.gz and yii-1.1.22.bf1d26.tar.gz

About: Yii is a high-performance component-based PHP framework for developing large-scale Web applications. Hint: Yii 1.1 is now in maintenance mode.

CJSON.php  (yii-1.1.21.733ac5):CJSON.php  (yii-1.1.22.bf1d26)
skipping to change at line 128 skipping to change at line 128
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 F ORMAT // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 F ORMAT
$ascii = ''; $ascii = '';
$strlen_var = strlen($var); $strlen_var = strlen($var);
/* /*
* Iterate over every character in the string, * Iterate over every character in the string,
* escaping with a slash or encoding to UTF-8 wher e necessary * escaping with a slash or encoding to UTF-8 wher e necessary
*/ */
for ($c = 0; $c < $strlen_var; ++$c) { for ($c = 0; $c < $strlen_var; ++$c) {
$ord_var_c = ord($var{$c}); $ord_var_c = ord($var[$c]);
switch (true) { switch (true) {
case $ord_var_c == 0x08: case $ord_var_c == 0x08:
$ascii .= '\b'; $ascii .= '\b';
break; break;
case $ord_var_c == 0x09: case $ord_var_c == 0x09:
$ascii .= '\t'; $ascii .= '\t';
break; break;
case $ord_var_c == 0x0A: case $ord_var_c == 0x0A:
$ascii .= '\n'; $ascii .= '\n';
skipping to change at line 151 skipping to change at line 151
$ascii .= '\f'; $ascii .= '\f';
break; break;
case $ord_var_c == 0x0D: case $ord_var_c == 0x0D:
$ascii .= '\r'; $ascii .= '\r';
break; break;
case $ord_var_c == 0x22: case $ord_var_c == 0x22:
case $ord_var_c == 0x2F: case $ord_var_c == 0x2F:
case $ord_var_c == 0x5C: case $ord_var_c == 0x5C:
// double quote, slash, s losh // double quote, slash, s losh
$ascii .= '\\'.$var{$c}; $ascii .= '\\'.$var[$c];
break; break;
case (($ord_var_c >= 0x20) && ($o rd_var_c <= 0x7F)): case (($ord_var_c >= 0x20) && ($o rd_var_c <= 0x7F)):
// characters U-00000000 - U-0000007F (same as ASCII) // characters U-00000000 - U-0000007F (same as ASCII)
$ascii .= $var{$c}; $ascii .= $var[$c];
break; break;
case (($ord_var_c & 0xE0) == 0xC0 ): case (($ord_var_c & 0xE0) == 0xC0 ):
// characters U-00000080 - U-000007FF, mask 110XXXXX // characters U-00000080 - U-000007FF, mask 110XXXXX
// see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8 // see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_v ar_c, ord($var{$c+1})); $char = pack('C*', $ord_v ar_c, ord($var[$c+1]));
$c+=1; $c+=1;
$utf16 = self::utf8ToUTF 16BE($char); $utf16 = self::utf8ToUTF 16BE($char);
$ascii .= sprintf('\u%04s ', bin2hex($utf16)); $ascii .= sprintf('\u%04s ', bin2hex($utf16));
break; break;
case (($ord_var_c & 0xF0) == 0xE0 ): case (($ord_var_c & 0xF0) == 0xE0 ):
// characters U-00000800 - U-0000FFFF, mask 1110XXXX // characters U-00000800 - U-0000FFFF, mask 1110XXXX
// see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8 // see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_v ar_c, $char = pack('C*', $ord_v ar_c,
ord($var{$c+1}), ord($var[$c+1]),
ord($var{$c+2})); ord($var[$c+2]));
$c+=2; $c+=2;
$utf16 = self::utf8ToUTF1 6BE($char); $utf16 = self::utf8ToUTF1 6BE($char);
$ascii .= sprintf('\u%04s ', bin2hex($utf16)); $ascii .= sprintf('\u%04s ', bin2hex($utf16));
break; break;
case (($ord_var_c & 0xF8) == 0xF0 ): case (($ord_var_c & 0xF8) == 0xF0 ):
// characters U-00010000 - U-001FFFFF, mask 11110XXX // characters U-00010000 - U-001FFFFF, mask 11110XXX
// see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8 // see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_v ar_c, $char = pack('C*', $ord_v ar_c,
ord($var{$c+1}), ord($var[$c+1]),
ord($var{$c+2}), ord($var[$c+2]),
ord($var{$c+3})); ord($var[$c+3]));
$c+=3; $c+=3;
$utf16 = self::utf8ToUTF1 6BE($char); $utf16 = self::utf8ToUTF1 6BE($char);
$ascii .= sprintf('\u%04s ', bin2hex($utf16)); $ascii .= sprintf('\u%04s ', bin2hex($utf16));
break; break;
case (($ord_var_c & 0xFC) == 0xF8 ): case (($ord_var_c & 0xFC) == 0xF8 ):
// characters U-00200000 - U-03FFFFFF, mask 111110XX // characters U-00200000 - U-03FFFFFF, mask 111110XX
// see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8 // see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_v ar_c, $char = pack('C*', $ord_v ar_c,
ord($var{$c+1}), ord($var[$c+1]),
ord($var{$c+2}), ord($var[$c+2]),
ord($var{$c+3}), ord($var[$c+3]),
ord($var{$c+4})); ord($var[$c+4]));
$c+=4; $c+=4;
$utf16 = self::utf8ToUTF1 6BE($char); $utf16 = self::utf8ToUTF1 6BE($char);
$ascii .= sprintf('\u%04s ', bin2hex($utf16)); $ascii .= sprintf('\u%04s ', bin2hex($utf16));
break; break;
case (($ord_var_c & 0xFE) == 0xFC ): case (($ord_var_c & 0xFE) == 0xFC ):
// characters U-04000000 - U-7FFFFFFF, mask 1111110X // characters U-04000000 - U-7FFFFFFF, mask 1111110X
// see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8 // see http://www.cl.cam. ac.uk/~mgk25/unicode.html#utf-8
$char = pack('C*', $ord_v ar_c, $char = pack('C*', $ord_v ar_c,
ord($var{$c+1}), ord($var[$c+1]),
ord($var{$c+2}), ord($var[$c+2]),
ord($var{$c+3}), ord($var[$c+3]),
ord($var{$c+4}), ord($var[$c+4]),
ord($var{$c+5})); ord($var[$c+5]));
$c+=5; $c+=5;
$utf16 = self::utf8ToUTF1 6BE($char); $utf16 = self::utf8ToUTF1 6BE($char);
$ascii .= sprintf('\u%04s ', bin2hex($utf16)); $ascii .= sprintf('\u%04s ', bin2hex($utf16));
break; break;
} }
} }
return '"'.$ascii.'"'; return '"'.$ascii.'"';
case 'array': case 'array':
skipping to change at line 379 skipping to change at line 379
} elseif (preg_match('/^("|\').+(\1)$/s', $str, $ m) && $m[1] == $m[2]) { } elseif (preg_match('/^("|\').+(\1)$/s', $str, $ m) && $m[1] == $m[2]) {
// STRINGS RETURNED IN UTF-8 FORMAT // STRINGS RETURNED IN UTF-8 FORMAT
$delim = substr($str, 0, 1); $delim = substr($str, 0, 1);
$chrs = substr($str, 1, -1); $chrs = substr($str, 1, -1);
$utf8 = ''; $utf8 = '';
$strlen_chrs = strlen($chrs); $strlen_chrs = strlen($chrs);
for ($c = 0; $c < $strlen_chrs; ++$c) { for ($c = 0; $c < $strlen_chrs; ++$c) {
$substr_chrs_c_2 = substr($chrs, $c, 2); $substr_chrs_c_2 = substr($chrs, $c, 2);
$ord_chrs_c = ord($chrs{$c}); $ord_chrs_c = ord($chrs[$c]);
switch (true) { switch (true) {
case $substr_chrs_c_2 == '\b': case $substr_chrs_c_2 == '\b':
$utf8 .= chr(0x08 ); $utf8 .= chr(0x08 );
++$c; ++$c;
break; break;
case $substr_chrs_c_2 == '\t': case $substr_chrs_c_2 == '\t':
$utf8 .= chr(0x09 ); $utf8 .= chr(0x09 );
++$c; ++$c;
break; break;
skipping to change at line 409 skipping to change at line 409
$utf8 .= chr(0x0D ); $utf8 .= chr(0x0D );
++$c; ++$c;
break; break;
case $substr_chrs_c_2 == '\\"': case $substr_chrs_c_2 == '\\"':
case $substr_chrs_c_2 == '\\\'': case $substr_chrs_c_2 == '\\\'':
case $substr_chrs_c_2 == '\\\\': case $substr_chrs_c_2 == '\\\\':
case $substr_chrs_c_2 == '\\/': case $substr_chrs_c_2 == '\\/':
if (($delim == '" ' && $substr_chrs_c_2 != '\\\'') || if (($delim == '" ' && $substr_chrs_c_2 != '\\\'') ||
($delim == "'" && $substr_chrs_c_2 != '\\"')) { ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
$utf8 .= $chrs{++$c}; $utf8 .= $chrs[++$c];
} }
break; break;
case preg_match('/\\\u[0- 9A-F]{4}/i', substr($chrs, $c, 6)): case preg_match('/\\\u[0- 9A-F]{4}/i', substr($chrs, $c, 6)):
// single, escape d unicode character // single, escape d unicode character
$utf16 = chr(hexd ec(substr($chrs, ($c+2), 2))) $utf16 = chr(hexd ec(substr($chrs, ($c+2), 2)))
. chr( hexdec(substr($chrs, ($c+4), 2))); . chr( hexdec(substr($chrs, ($c+4), 2)));
$utf8 .= self::ut f16beToUTF8($utf16); $utf8 .= self::ut f16beToUTF8($utf16);
$c+=5; $c+=5;
break; break;
case ($ord_chrs_c >= 0x20 ) && ($ord_chrs_c <= 0x7F): case ($ord_chrs_c >= 0x20 ) && ($ord_chrs_c <= 0x7F):
$utf8 .= $chrs{$c }; $utf8 .= $chrs[$c ];
break; break;
case ($ord_chrs_c & 0xE0) == 0xC0: case ($ord_chrs_c & 0xE0) == 0xC0:
// characters U-0 0000080 - U-000007FF, mask 110XXXXX // characters U-0 0000080 - U-000007FF, mask 110XXXXX
//see http://www. cl.cam.ac.uk/~mgk25/unicode.html#utf-8 //see http://www. cl.cam.ac.uk/~mgk25/unicode.html#utf-8
$utf8 .= substr($ chrs, $c, 2); $utf8 .= substr($ chrs, $c, 2);
++$c; ++$c;
break; break;
case ($ord_chrs_c & 0xF0) == 0xE0: case ($ord_chrs_c & 0xF0) == 0xE0:
skipping to change at line 469 skipping to change at line 469
} }
} }
return $utf8; return $utf8;
} elseif (preg_match('/^\[.*\]$/s', $str) || preg _match('/^\{.*\}$/s', $str)) { } elseif (preg_match('/^\[.*\]$/s', $str) || preg _match('/^\{.*\}$/s', $str)) {
// array, or object notation // array, or object notation
if ($str{0} == '[') { if ($str[0] == '[') {
$stk = array(self::JSON_IN_ARR); $stk = array(self::JSON_IN_ARR);
$arr = array(); $arr = array();
} else { } else {
if ($useArray) { if ($useArray) {
$stk = array(self::JSON_I N_OBJ); $stk = array(self::JSON_I N_OBJ);
$obj = array(); $obj = array();
} else { } else {
$stk = array(self::JSON_I N_OBJ); $stk = array(self::JSON_I N_OBJ);
$obj = new stdClass(); $obj = new stdClass();
} }
skipping to change at line 506 skipping to change at line 506
//print("\nparsing {$chrs}\n"); //print("\nparsing {$chrs}\n");
$strlen_chrs = strlen($chrs); $strlen_chrs = strlen($chrs);
for ($c = 0; $c <= $strlen_chrs; ++$c) { for ($c = 0; $c <= $strlen_chrs; ++$c) {
$top = end($stk); $top = end($stk);
$substr_chrs_c_2 = substr($chrs, $c, 2); $substr_chrs_c_2 = substr($chrs, $c, 2);
if (($c == $strlen_chrs) || (($ch rs{$c} == ',') && ($top['what'] == self::JSON_SLICE))) { if (($c == $strlen_chrs) || (($ch rs[$c] == ',') && ($top['what'] == self::JSON_SLICE))) {
// found a comma that is not inside a string, array, etc., // found a comma that is not inside a string, array, etc.,
// OR we've reached the e nd of the character list // OR we've reached the e nd of the character list
$slice = substr($chrs, $t op['where'], ($c - $top['where'])); $slice = substr($chrs, $t op['where'], ($c - $top['where']));
$stk[] = array('what' => self::JSON_SLICE, 'where' => ($c + 1), 'delim' => false); $stk[] = array('what' => self::JSON_SLICE, 'where' => ($c + 1), 'delim' => false);
//print("Found split at { $c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); //print("Found split at { $c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
if (reset($stk) == self:: JSON_IN_ARR) { if (reset($stk) == self:: JSON_IN_ARR) {
// we are in an a rray, so just push an element onto the stack // we are in an a rray, so just push an element onto the stack
$arr[] = self::de code($slice,$useArray); $arr[] = self::de code($slice,$useArray);
skipping to change at line 546 skipping to change at line 546
if ($useA rray) { if ($useA rray) {
$ obj[$key] = $val; $ obj[$key] = $val;
} else { } else {
$ obj->$key = $val; $ obj->$key = $val;
} }
} }
} }
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != self::JSON_IN_STR)) { } elseif ((($chrs[$c] == '"') || ($chrs[$c] == "'")) && ($top['what'] != self::JSON_IN_STR)) {
// found a quote, and we are not inside a string // found a quote, and we are not inside a string
$stk[] = array('what' => self::JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}); $stk[] = array('what' => self::JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]);
//print("Found start of s tring at {$c}\n"); //print("Found start of s tring at {$c}\n");
} elseif (($chrs{$c} == $top['del im']) && } elseif (($chrs[$c] == $top['del im']) &&
($top['what'] == self::JSON_IN_STR) && ($top['what'] == self::JSON_IN_STR) &&
(($chrs{$c - 1} (($chrs[$c - 1]
!= "\\") || != "\\") ||
($chrs{$c - 1} = ($chrs[$c - 1] =
= "\\" && $chrs{$c - 2} == "\\"))) { = "\\" && $chrs[$c - 2] == "\\"))) {
// found a quote, we're i n a string, and it's not escaped // found a quote, we're i n a string, and it's not escaped
array_pop($stk); array_pop($stk);
//print("Found end of str ing at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); //print("Found end of str ing at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
} elseif (($chrs{$c} == '[') && } elseif (($chrs[$c] == '[') &&
in_array($top['w hat'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) { in_array($top['w hat'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
// found a left-bracket, and we are in an array, object, or slice // found a left-bracket, and we are in an array, object, or slice
$stk[] = array('what' => self::JSON_IN_ARR, 'where' => $c, 'delim' => false); $stk[] = array('what' => self::JSON_IN_ARR, 'where' => $c, 'delim' => false);
//print("Found start of a rray at {$c}\n"); //print("Found start of a rray at {$c}\n");
} elseif (($chrs{$c} == ']') && ( $top['what'] == self::JSON_IN_ARR)) { } elseif (($chrs[$c] == ']') && ( $top['what'] == self::JSON_IN_ARR)) {
// found a right-bracket, and we're in an array // found a right-bracket, and we're in an array
array_pop($stk); array_pop($stk);
//print("Found end of arr ay at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); //print("Found end of arr ay at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
} elseif (($chrs{$c} == '{') && } elseif (($chrs[$c] == '{') &&
in_array($top['w hat'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) { in_array($top['w hat'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
// found a left-brace, an d we are in an array, object, or slice // found a left-brace, an d we are in an array, object, or slice
$stk[] = array('what' => self::JSON_IN_OBJ, 'where' => $c, 'delim' => false); $stk[] = array('what' => self::JSON_IN_OBJ, 'where' => $c, 'delim' => false);
//print("Found start of o bject at {$c}\n"); //print("Found start of o bject at {$c}\n");
} elseif (($chrs{$c} == '}') && ( $top['what'] == self::JSON_IN_OBJ)) { } elseif (($chrs[$c] == '}') && ( $top['what'] == self::JSON_IN_OBJ)) {
// found a right-brace, a nd we're in an object // found a right-brace, a nd we're in an object
array_pop($stk); array_pop($stk);
//print("Found end of obj ect at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); //print("Found end of obj ect at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
} elseif (($substr_chrs_c_2 == '/ *') && } elseif (($substr_chrs_c_2 == '/ *') &&
in_array($top['w hat'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) { in_array($top['w hat'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
// found a comment start, and we are in an array, object, or slice // found a comment start, and we are in an array, object, or slice
$stk[] = array('what' => self::JSON_IN_CMT, 'where' => $c, 'delim' => false); $stk[] = array('what' => self::JSON_IN_CMT, 'where' => $c, 'delim' => false);
$c++; $c++;
//print("Found start of c omment at {$c}\n"); //print("Found start of c omment at {$c}\n");
 End of changes. 21 change blocks. 
48 lines changed or deleted 48 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)