| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
define('SERVICES_JSON_SLICE', 1); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
define('SERVICES_JSON_IN_STR', 2); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
define('SERVICES_JSON_IN_ARR', 4); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
define('SERVICES_JSON_IN_OBJ', 8); |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
define('SERVICES_JSON_IN_CMT', 16); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
define('SERVICES_JSON_LOOSE_TYPE', 10); |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
define('SERVICES_JSON_STRICT_TYPE', 11); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
define('SERVICES_JSON_ISO_8859_1', 'iso-8859-1'); |
| 97 |
define('SERVICES_JSON_UTF_8', 'utf-8'); |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
class Services_JSON |
| 121 |
{ |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
function Services_JSON($encoding = SERVICES_JSON_UTF_8, $use = SERVICES_JSON_STRICT_TYPE) |
| 140 |
{ |
| 141 |
|
| 142 |
$this->encoding = $encoding; |
| 143 |
|
| 144 |
|
| 145 |
$this->use = $use; |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
function utf162utf8($utf16) |
| 160 |
{ |
| 161 |
|
| 162 |
if(function_exists('mb_convert_encoding')) |
| 163 |
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
| 164 |
|
| 165 |
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); |
| 166 |
|
| 167 |
switch(true) { |
| 168 |
case ((0x7F & $bytes) == $bytes): |
| 169 |
|
| 170 |
|
| 171 |
return chr(0x7F & $bytes); |
| 172 |
|
| 173 |
case (0x07FF & $bytes) == $bytes: |
| 174 |
|
| 175 |
|
| 176 |
return chr(0xC0 | (($bytes >> 6) & 0x1F)) |
| 177 |
. chr(0x80 | ($bytes & 0x3F)); |
| 178 |
|
| 179 |
case (0xFFFF & $bytes) == $bytes: |
| 180 |
|
| 181 |
|
| 182 |
return chr(0xE0 | (($bytes >> 12) & 0x0F)) |
| 183 |
. chr(0x80 | (($bytes >> 6) & 0x3F)) |
| 184 |
. chr(0x80 | ($bytes & 0x3F)); |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
return ''; |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
function utf82utf16($utf8) |
| 203 |
{ |
| 204 |
|
| 205 |
if(function_exists('mb_convert_encoding')) |
| 206 |
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
| 207 |
|
| 208 |
switch(strlen($utf8)) { |
| 209 |
case 1: |
| 210 |
|
| 211 |
|
| 212 |
return $utf8; |
| 213 |
|
| 214 |
case 2: |
| 215 |
|
| 216 |
|
| 217 |
return chr(0x07 & (ord($utf8{0}) >> 2)) |
| 218 |
. chr((0xC0 & (ord($utf8{0}) << 6)) |
| 219 |
| (0x3F & ord($utf8{1}))); |
| 220 |
|
| 221 |
case 3: |
| 222 |
|
| 223 |
|
| 224 |
return chr((0xF0 & (ord($utf8{0}) << 4)) |
| 225 |
| (0x0F & (ord($utf8{1}) >> 2))) |
| 226 |
. chr((0xC0 & (ord($utf8{1}) << 6)) |
| 227 |
| (0x7F & ord($utf8{2}))); |
| 228 |
} |
| 229 |
|
| 230 |
|
| 231 |
return ''; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
function encode($var) |
| 246 |
{ |
| 247 |
switch (gettype($var)) { |
| 248 |
case 'boolean': |
| 249 |
return $var ? 'true' : 'false'; |
| 250 |
|
| 251 |
case 'NULL': |
| 252 |
return 'null'; |
| 253 |
|
| 254 |
case 'integer': |
| 255 |
return (int) $var; |
| 256 |
|
| 257 |
case 'double': |
| 258 |
case 'float': |
| 259 |
return (float) $var; |
| 260 |
|
| 261 |
case 'string': |
| 262 |
|
| 263 |
if ($this->encoding == SERVICES_JSON_UTF_8) |
| 264 |
; |
| 265 |
else if ($this->encoding == SERVICES_JSON_ISO_8859_1) |
| 266 |
$var = utf8_encode($var); |
| 267 |
else if (!function_exists('mb_convert_encoding')) |
| 268 |
die('Requested encoding requires mb_strings extension.'); |
| 269 |
else |
| 270 |
$var = mb_convert_encoding($var, "utf-8", $this->encoding); |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
$ascii = ''; |
| 275 |
$strlen_var = strlen($var); |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
for ($c = 0; $c < $strlen_var; ++$c) { |
| 282 |
|
| 283 |
$ord_var_c = ord($var{$c}); |
| 284 |
|
| 285 |
switch (true) { |
| 286 |
case $ord_var_c == 0x08: |
| 287 |
$ascii .= '\b'; |
| 288 |
break; |
| 289 |
case $ord_var_c == 0x09: |
| 290 |
$ascii .= '\t'; |
| 291 |
break; |
| 292 |
case $ord_var_c == 0x0A: |
| 293 |
$ascii .= '\n'; |
| 294 |
break; |
| 295 |
case $ord_var_c == 0x0C: |
| 296 |
$ascii .= '\f'; |
| 297 |
break; |
| 298 |
case $ord_var_c == 0x0D: |
| 299 |
$ascii .= '\r'; |
| 300 |
break; |
| 301 |
|
| 302 |
case $ord_var_c == 0x22: |
| 303 |
case $ord_var_c == 0x2F: |
| 304 |
case $ord_var_c == 0x5C: |
| 305 |
|
| 306 |
$ascii .= '\\'.$var{$c}; |
| 307 |
break; |
| 308 |
|
| 309 |
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
| 310 |
|
| 311 |
$ascii .= $var{$c}; |
| 312 |
break; |
| 313 |
|
| 314 |
case (($ord_var_c & 0xE0) == 0xC0): |
| 315 |
|
| 316 |
|
| 317 |
$char = pack('C*', $ord_var_c, ord($var{$c + 1})); |
| 318 |
$c += 1; |
| 319 |
$utf16 = $this->utf82utf16($char); |
| 320 |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 321 |
break; |
| 322 |
|
| 323 |
case (($ord_var_c & 0xF0) == 0xE0): |
| 324 |
|
| 325 |
|
| 326 |
$char = pack('C*', $ord_var_c, |
| 327 |
ord($var{$c + 1}), |
| 328 |
ord($var{$c + 2})); |
| 329 |
$c += 2; |
| 330 |
$utf16 = $this->utf82utf16($char); |
| 331 |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 332 |
break; |
| 333 |
|
| 334 |
case (($ord_var_c & 0xF8) == 0xF0): |
| 335 |
|
| 336 |
|
| 337 |
$char = pack('C*', $ord_var_c, |
| 338 |
ord($var{$c + 1}), |
| 339 |
ord($var{$c + 2}), |
| 340 |
ord($var{$c + 3})); |
| 341 |
$c += 3; |
| 342 |
$utf16 = $this->utf82utf16($char); |
| 343 |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 344 |
break; |
| 345 |
|
| 346 |
case (($ord_var_c & 0xFC) == 0xF8): |
| 347 |
|
| 348 |
|
| 349 |
$char = pack('C*', $ord_var_c, |
| 350 |
ord($var{$c + 1}), |
| 351 |
ord($var{$c + 2}), |
| 352 |
ord($var{$c + 3}), |
| 353 |
ord($var{$c + 4})); |
| 354 |
$c += 4; |
| 355 |
$utf16 = $this->utf82utf16($char); |
| 356 |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 357 |
break; |
| 358 |
|
| 359 |
case (($ord_var_c & 0xFE) == 0xFC): |
| 360 |
|
| 361 |
|
| 362 |
$char = pack('C*', $ord_var_c, |
| 363 |
ord($var{$c + 1}), |
| 364 |
ord($var{$c + 2}), |
| 365 |
ord($var{$c + 3}), |
| 366 |
ord($var{$c + 4}), |
| 367 |
ord($var{$c + 5})); |
| 368 |
$c += 5; |
| 369 |
$utf16 = $this->utf82utf16($char); |
| 370 |
$ascii .= sprintf('\u%04s', bin2hex($utf16)); |
| 371 |
break; |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
return '"'.$ascii.'"'; |
| 376 |
|
| 377 |
case 'array': |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { |
| 398 |
return '{' . |
| 399 |
join(',', array_map(array($this, 'name_value'), |
| 400 |
array_keys($var), |
| 401 |
array_values($var))) |
| 402 |
. '}'; |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
return '[' . join(',', array_map(array($this, 'encode'), $var)) . ']'; |
| 407 |
|
| 408 |
case 'object': |
| 409 |
$vars = get_object_vars($var); |
| 410 |
return '{' . |
| 411 |
join(',', array_map(array($this, 'name_value'), |
| 412 |
array_keys($vars), |
| 413 |
array_values($vars))) |
| 414 |
. '}'; |
| 415 |
|
| 416 |
default: |
| 417 |
return ''; |
| 418 |
} |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
function name_value($name, $value) |
| 431 |
{ |
| 432 |
return $this->encode(strval($name)) . ':' . $this->encode($value); |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
function reduce_string($str) |
| 444 |
{ |
| 445 |
$str = preg_replace(array( |
| 446 |
|
| 447 |
|
| 448 |
' |
| 449 |
|
| 450 |
|
| 451 |
' |
| 452 |
|
| 453 |
|
| 454 |
' |
| 455 |
|
| 456 |
), '', $str); |
| 457 |
|
| 458 |
|
| 459 |
return trim($str); |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
function decode($str) |
| 475 |
{ |
| 476 |
$str = $this->reduce_string($str); |
| 477 |
|
| 478 |
switch (strtolower($str)) { |
| 479 |
case 'true': |
| 480 |
return true; |
| 481 |
|
| 482 |
case 'false': |
| 483 |
return false; |
| 484 |
|
| 485 |
case 'null': |
| 486 |
return null; |
| 487 |
|
| 488 |
default: |
| 489 |
if (is_numeric($str)) { |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
return ((float)$str == (integer)$str) |
| 498 |
? (integer)$str |
| 499 |
: (float)$str; |
| 500 |
|
| 501 |
} elseif (preg_match('/^("|\').+(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
| 502 |
|
| 503 |
$delim = substr($str, 0, 1); |
| 504 |
$chrs = substr($str, 1, -1); |
| 505 |
$utf8 = ''; |
| 506 |
$strlen_chrs = strlen($chrs); |
| 507 |
|
| 508 |
for ($c = 0; $c < $strlen_chrs; ++$c) { |
| 509 |
|
| 510 |
$substr_chrs_c_2 = substr($chrs, $c, 2); |
| 511 |
$ord_chrs_c = ord($chrs{$c}); |
| 512 |
|
| 513 |
switch (true) { |
| 514 |
case $substr_chrs_c_2 == '\b': |
| 515 |
$utf8 .= chr(0x08); |
| 516 |
++$c; |
| 517 |
break; |
| 518 |
case $substr_chrs_c_2 == '\t': |
| 519 |
$utf8 .= chr(0x09); |
| 520 |
++$c; |
| 521 |
break; |
| 522 |
case $substr_chrs_c_2 == '\n': |
| 523 |
$utf8 .= chr(0x0A); |
| 524 |
++$c; |
| 525 |
break; |
| 526 |
case $substr_chrs_c_2 == '\f': |
| 527 |
$utf8 .= chr(0x0C); |
| 528 |
++$c; |
| 529 |
break; |
| 530 |
case $substr_chrs_c_2 == '\r': |
| 531 |
$utf8 .= chr(0x0D); |
| 532 |
++$c; |
| 533 |
break; |
| 534 |
|
| 535 |
case $substr_chrs_c_2 == '\\"': |
| 536 |
case $substr_chrs_c_2 == '\\\'': |
| 537 |
case $substr_chrs_c_2 == '\\\\': |
| 538 |
case $substr_chrs_c_2 == '\\/': |
| 539 |
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') || |
| 540 |
($delim == "'" && $substr_chrs_c_2 != '\\"')) { |
| 541 |
$utf8 .= $chrs{++$c}; |
| 542 |
} |
| 543 |
break; |
| 544 |
|
| 545 |
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)): |
| 546 |
|
| 547 |
|
| 548 |
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2))) |
| 549 |
. chr(hexdec(substr($chrs, ($c + 4), 2))); |
| 550 |
$utf8 .= $this->utf162utf8($utf16); |
| 551 |
$c += 5; |
| 552 |
break; |
| 553 |
|
| 554 |
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
| 555 |
$utf8 .= $chrs{$c}; |
| 556 |
break; |
| 557 |
|
| 558 |
case ($ord_chrs_c & 0xE0) == 0xC0: |
| 559 |
|
| 560 |
|
| 561 |
$utf8 .= substr($chrs, $c, 2); |
| 562 |
++$c; |
| 563 |
break; |
| 564 |
|
| 565 |
case ($ord_chrs_c & 0xF0) == 0xE0: |
| 566 |
|
| 567 |
|
| 568 |
$utf8 .= substr($chrs, $c, 3); |
| 569 |
$c += 2; |
| 570 |
break; |
| 571 |
|
| 572 |
case ($ord_chrs_c & 0xF8) == 0xF0: |
| 573 |
|
| 574 |
|
| 575 |
$utf8 .= substr($chrs, $c, 4); |
| 576 |
$c += 3; |
| 577 |
break; |
| 578 |
|
| 579 |
case ($ord_chrs_c & 0xFC) == 0xF8: |
| 580 |
|
| 581 |
|
| 582 |
$utf8 .= substr($chrs, $c, 5); |
| 583 |
$c += 4; |
| 584 |
break; |
| 585 |
|
| 586 |
case ($ord_chrs_c & 0xFE) == 0xFC: |
| 587 |
|
| 588 |
|
| 589 |
$utf8 .= substr($chrs, $c, 6); |
| 590 |
$c += 5; |
| 591 |
break; |
| 592 |
|
| 593 |
} |
| 594 |
|
| 595 |
} |
| 596 |
|
| 597 |
|
| 598 |
if ($this->encoding == SERVICES_JSON_UTF_8) |
| 599 |
return $utf8; |
| 600 |
if ($this->encoding == SERVICES_JSON_ISO_8859_1) |
| 601 |
return utf8_decode($utf8); |
| 602 |
else if (!function_exists('mb_convert_encoding')) |
| 603 |
die('Requested encoding requires mb_strings extension.'); |
| 604 |
else |
| 605 |
return mb_convert_encoding($utf8, $this->encoding, SERVICES_JSON_UTF_8); |
| 606 |
|
| 607 |
|
| 608 |
return $utf8; |
| 609 |
|
| 610 |
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
| 611 |
|
| 612 |
if ($str{0} == '[') { |
| 613 |
$stk = array(SERVICES_JSON_IN_ARR); |
| 614 |
$arr = array(); |
| 615 |
} else { |
| 616 |
if ($this->use == SERVICES_JSON_LOOSE_TYPE) { |
| 617 |
$stk = array(SERVICES_JSON_IN_OBJ); |
| 618 |
$obj = array(); |
| 619 |
} else { |
| 620 |
$stk = array(SERVICES_JSON_IN_OBJ); |
| 621 |
$obj = new stdClass(); |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
array_push($stk, array('what' => SERVICES_JSON_SLICE, |
| 626 |
'where' => 0, |
| 627 |
'delim' => false)); |
| 628 |
|
| 629 |
$chrs = substr($str, 1, -1); |
| 630 |
$chrs = $this->reduce_string($chrs); |
| 631 |
|
| 632 |
if ($chrs == '') { |
| 633 |
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
| 634 |
return $arr; |
| 635 |
|
| 636 |
} else { |
| 637 |
return $obj; |
| 638 |
|
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
$strlen_chrs = strlen($chrs); |
| 645 |
for ($c = 0; $c <= $strlen_chrs; ++$c) { |
| 646 |
|
| 647 |
$top = end($stk); |
| 648 |
$substr_chrs_c_2 = substr($chrs, $c, 2); |
| 649 |
|
| 650 |
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { |
| 651 |
|
| 652 |
|
| 653 |
$slice = substr($chrs, $top['where'], ($c - $top['where'])); |
| 654 |
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false)); |
| 655 |
|
| 656 |
|
| 657 |
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
| 658 |
|
| 659 |
array_push($arr, $this->decode($slice)); |
| 660 |
|
| 661 |
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { |
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
| 667 |
|
| 668 |
$key = $this->decode($parts[1]); |
| 669 |
$val = $this->decode($parts[2]); |
| 670 |
|
| 671 |
if ($this->use == SERVICES_JSON_LOOSE_TYPE) { |
| 672 |
$obj[$key] = $val; |
| 673 |
} else { |
| 674 |
$obj->$key = $val; |
| 675 |
} |
| 676 |
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
| 677 |
|
| 678 |
$key = $parts[1]; |
| 679 |
$val = $this->decode($parts[2]); |
| 680 |
|
| 681 |
if ($this->use == SERVICES_JSON_LOOSE_TYPE) { |
| 682 |
$obj[$key] = $val; |
| 683 |
} else { |
| 684 |
$obj->$key = $val; |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
} |
| 689 |
|
| 690 |
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { |
| 691 |
|
| 692 |
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
} elseif ($chrs{$c} == $top['delim'] && |
| 701 |
$top['what'] == SERVICES_JSON_IN_STR) { |
| 702 |
|
| 703 |
|
| 704 |
for ($i=0; ($chrs{$c - ($i+1)} == '\\'); $i++); |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
if ($i % 2 != 0) |
| 710 |
{ |
| 711 |
|
| 712 |
continue; |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
array_pop($stk); |
| 717 |
|
| 718 |
|
| 719 |
} elseif (($chrs{$c} == '[') && |
| 720 |
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
| 721 |
|
| 722 |
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false)); |
| 723 |
|
| 724 |
|
| 725 |
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { |
| 726 |
|
| 727 |
array_pop($stk); |
| 728 |
|
| 729 |
|
| 730 |
} elseif (($chrs{$c} == '{') && |
| 731 |
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
| 732 |
|
| 733 |
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false)); |
| 734 |
|
| 735 |
|
| 736 |
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { |
| 737 |
|
| 738 |
array_pop($stk); |
| 739 |
|
| 740 |
|
| 741 |
} elseif (($substr_chrs_c_2 == '/*') && |
| 742 |
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
| 743 |
|
| 744 |
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false)); |
| 745 |
$c++; |
| 746 |
|
| 747 |
|
| 748 |
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) { |
| 749 |
|
| 750 |
array_pop($stk); |
| 751 |
$c++; |
| 752 |
|
| 753 |
for ($i = $top['where']; $i <= $c; ++$i) |
| 754 |
$chrs = substr_replace($chrs, ' ', $i, 1); |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
} |
| 759 |
|
| 760 |
} |
| 761 |
|
| 762 |
if (reset($stk) == SERVICES_JSON_IN_ARR) { |
| 763 |
return $arr; |
| 764 |
|
| 765 |
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) { |
| 766 |
return $obj; |
| 767 |
|
| 768 |
} |
| 769 |
|
| 770 |
} |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
} |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
?> |