39 public static function format($json, $unescapeUnicode, $unescapeSlashes)
43 $strLen = strlen($json);
50 for (
$i = 0;
$i < $strLen; ++
$i) {
52 $char = substr($json,
$i, 1);
55 if (
'"' === $char && $noescape) {
56 $outOfQuotes = !$outOfQuotes;
61 $noescape =
'\\' === $char ? !$noescape :
true;
63 } elseif (
'' !== $buffer) {
64 if ($unescapeSlashes) {
65 $buffer = str_replace(
'\\/',
'/', $buffer);
68 if ($unescapeUnicode && function_exists(
'mb_convert_encoding')) {
70 $buffer = preg_replace_callback(
'/(\\\\+)u([0-9a-f]{4})/i',
function ($match) {
71 $l = strlen($match[1]);
74 return str_repeat(
'\\',
$l - 1) . mb_convert_encoding(
75 pack(
'H*', $match[2]),
93 } elseif ((
'}' === $char ||
']' === $char)) {
95 $prevChar = substr($json,
$i - 1, 1);
97 if (
'{' !== $prevChar &&
'[' !== $prevChar) {
101 for (
$j = 0;
$j < $pos; ++
$j) {
114 if (
',' === $char ||
'{' === $char ||
'[' === $char) {
117 if (
'{' === $char ||
'[' === $char) {
121 for (
$j = 0;
$j < $pos; ++
$j) {