function name_value($name, $value) { return (sprintf("%s:%s", $this->encode(strval($name)), $this->encode($value))); }
function reduce_string($str) { $str = preg_replace("#^s*//(.+)$#m", "", $str); // eliminate single line comments in "// ..." form $str = preg_replace("#^s*/*(.+)*/#Us", "", $str); // eliminate multi-line comments in "/* ... */" form, at start of string $str = preg_replace("#/*(.+)*/s*$#Us", "", $str); // eliminate multi-line comments in "/* ... */" form, at end of string $str = trim($str); // eliminate extraneous space
return $str; }
function decode($str) { $str = $this->reduce_string($str);
switch(strtolower($str)) { case "true": return true;
if(reset($stk) == HTML_AJAX_JSON_IN_ARR) { // we are in an array, so just push an element onto the stack array_push($arr, $this->decode($slice));
} elseif(reset($stk) == HTML_AJAX_JSON_IN_OBJ) { // we are in an object, so figure out the property name and set an element in an associative array, for now if(preg_match("/^s*([""].*[^\][""])s*:s*(S.*),?$/Uis", $slice, $parts)) { // "name":value pair $key = $this->decode($parts[1]); $val = $this->decode($parts[2]);
} elseif((($chrs{$c} == """) || ($chrs{$c} == """)) && ($top["what"] != HTML_AJAX_JSON_IN_STR)) { // found a quote, and we are not inside a string array_push($stk, array("what" => HTML_AJAX_JSON_IN_STR, "where" => $c, "delim" => $chrs{$c})); //print("Found start of string at {$c}
");
} elseif(($chrs{$c} == $top["delim"]) && ($top["what"] == HTML_AJAX_JSON_IN_STR) && (($chrs{$c - 1} != "\") || ($chrs{$c - 1} == "\" && $chrs{$c - 2} == "\"))) { // found a quote, we"re in a string, and it"s not escaped array_pop($stk); //print("Found end of string at {$c}: ".substr($chrs, $top["where"], (1 + 1 + $c - $top["where"]))."
");
} elseif(($chrs{$c} == "[") && in_array($top["what"], array(HTML_AJAX_JSON_SLICE, HTML_AJAX_JSON_IN_ARR, HTML_AJAX_JSON_IN_OBJ))) { // found a left-bracket, and we are in an array, object, or slice array_push($stk, array("what" => HTML_AJAX_JSON_IN_ARR, "where" => $c, "delim" => false)); //print("Found start of array at {$c}
");
} elseif(($chrs{$c} == "]") && ($top["what"] == HTML_AJAX_JSON_IN_ARR)) { // found a right-bracket, and we"re in an array array_pop($stk); //print("Found end of array at {$c}: ".substr($chrs, $top["where"], (1 + $c - $top["where"]))."
");
} elseif(($chrs{$c} == "{") && in_array($top["what"], array(HTML_AJAX_JSON_SLICE, HTML_AJAX_JSON_IN_ARR, HTML_AJAX_JSON_IN_OBJ))) { // found a left-brace, and we are in an array, object, or slice array_push($stk, array("what" => HTML_AJAX_JSON_IN_OBJ, "where" => $c, "delim" => false)); //print("Found start of object at {$c}
");
} elseif(($chrs{$c} == "}") && ($top["what"] == HTML_AJAX_JSON_IN_OBJ)) { // found a right-brace, and we"re in an object array_pop($stk); //print("Found end of object at {$c}: ".substr($chrs, $top["where"], (1 + $c - $top["where"]))."
");
} elseif(($substr_chrs_c_2 == "/*") && in_array($top["what"], array(HTML_AJAX_JSON_SLICE, HTML_AJAX_JSON_IN_ARR, HTML_AJAX_JSON_IN_OBJ))) { // found a comment start, and we are in an array, object, or slice array_push($stk, array("what" => HTML_AJAX_JSON_IN_CMT, "where" => $c, "delim" => false)); $c++; //print("Found start of comment at {$c}
");
} elseif(($substr_chrs_c_2 == "*/") && ($top["what"] == HTML_AJAX_JSON_IN_CMT)) { // found a comment end, and we"re in one now array_pop($stk); $c++;