jani Tue Jul 22 15:30:33 2008 UTC
Modified files:
/php-src/ext/json json.c
Log:
ws + cs + sync with PHP_5_3
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.36&r2=1.37&diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.36 php-src/ext/json/json.c:1.37
--- php-src/ext/json/json.c:1.36 Fri Jun 27 19:17:29 2008
+++ php-src/ext/json/json.c Tue Jul 22 15:30:33 2008
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: json.c,v 1.36 2008/06/27 19:17:29 felipe Exp $ */
+/* $Id: json.c,v 1.37 2008/07/22 15:30:33 jani Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -30,6 +30,10 @@
#include "JSON_parser.h"
#include "php_json.h"
+static PHP_MINFO_FUNCTION(json);
+static PHP_FUNCTION(json_encode);
+static PHP_FUNCTION(json_decode);
+
static const char digits[] = "0123456789abcdef";
#define PHP_JSON_HEX_TAG (1<<0)
@@ -54,10 +58,10 @@
*
* Every user visible function must have an entry in json_functions[].
*/
-const function_entry json_functions[] = {
- PHP_FE(json_encode, arginfo_json_encode)
- PHP_FE(json_decode, arginfo_json_decode)
- {NULL, NULL, NULL} /* Must be the last line in json_functions[] */
+static const function_entry json_functions[] = {
+ PHP_FE(json_encode, arginfo_json_encode)
+ PHP_FE(json_decode, arginfo_json_decode)
+ {NULL, NULL, NULL}
};
/* }}} */
@@ -100,7 +104,7 @@
/* {{{ PHP_MINFO_FUNCTION
*/
-PHP_MINFO_FUNCTION(json)
+static PHP_MINFO_FUNCTION(json)
{
php_info_print_table_start();
php_info_print_table_row(2, "json support", "enabled");
@@ -165,17 +169,16 @@
return;
}
- if (r == 0)
- {
+ if (r == 0) {
smart_str_appendc(buf, '[');
- }
- else
- {
+ } else {
smart_str_appendc(buf, '{');
}
i = myht ? zend_hash_num_elements(myht) : 0;
- if (i > 0) {
+
+ if (i > 0)
+ {
zstr key;
zval **data;
ulong index;
@@ -205,8 +208,7 @@
json_encode_r(buf, *data, options
TSRMLS_CC);
} else if (r == 1) {
- if (i == HASH_KEY_IS_STRING ||
- i == HASH_KEY_IS_UNICODE) {
+ if (i == HASH_KEY_IS_STRING || i ==
HASH_KEY_IS_UNICODE) {
if (key.s[0] == '\0' &&
Z_TYPE_PP(val) == IS_OBJECT) {
/* Skip protected and
private members. */
continue;
@@ -218,7 +220,7 @@
need_comma = 1;
}
- json_escape_string(buf, key,
key_len - 1, (i==HASH_KEY_IS_UNICODE)?IS_UNICODE:IS_STRING, options TSRMLS_CC);
+ json_escape_string(buf, key,
key_len - 1, (i == HASH_KEY_IS_UNICODE) ? IS_UNICODE : IS_STRING, options
TSRMLS_CC);
smart_str_appendc(buf, ':');
json_encode_r(buf, *data,
options TSRMLS_CC);
@@ -228,7 +230,7 @@
} else {
need_comma = 1;
}
-
+
smart_str_appendc(buf, '"');
smart_str_append_long(buf,
(long) index);
smart_str_appendc(buf, '"');
@@ -245,12 +247,9 @@
}
}
- if (r == 0)
- {
+ if (r == 0) {
smart_str_appendc(buf, ']');
- }
- else
- {
+ } else {
smart_str_appendc(buf, '}');
}
}
@@ -264,25 +263,23 @@
unsigned short us;
unsigned short *utf16;
- if (len == 0)
- {
+ if (len == 0) {
smart_str_appendl(buf, "\"\"", 2);
return;
}
if (type == IS_UNICODE) {
utf16 = (unsigned short *) s.u;
- } else {
+ } else {
utf16 = (unsigned short *) safe_emalloc(len, sizeof(unsigned
short), 0);
len = utf8_to_utf16(utf16, s.s, len);
- if (len <= 0)
- {
+ if (len <= 0) {
if (utf16) {
efree(utf16);
}
- if(len < 0) {
- if(!PG(display_errors)) {
+ if (len < 0) {
+ if (!PG(display_errors)) {
php_error_docref(NULL TSRMLS_CC,
E_WARNING, "Invalid UTF-8 sequence in argument");
}
smart_str_appendl(buf, "null", 4);
@@ -295,111 +292,94 @@
smart_str_appendc(buf, '"');
- while(pos < len)
+ while (pos < len)
{
us = utf16[pos++];
switch (us)
{
case '"':
- {
- if (options & PHP_JSON_HEX_QUOT) {
- smart_str_appendl(buf,
"\\u0022", 6);
- } else {
- smart_str_appendl(buf, "\\\"",
2);
- }
+ if (options & PHP_JSON_HEX_QUOT) {
+ smart_str_appendl(buf, "\\u0022", 6);
+ } else {
+ smart_str_appendl(buf, "\\\"", 2);
}
break;
+
case '\\':
- {
- smart_str_appendl(buf, "\\\\", 2);
- }
+ smart_str_appendl(buf, "\\\\", 2);
break;
+
case '/':
- {
- smart_str_appendl(buf, "\\/", 2);
- }
+ smart_str_appendl(buf, "\\/", 2);
break;
+
case '\b':
- {
- smart_str_appendl(buf, "\\b", 2);
- }
+ smart_str_appendl(buf, "\\b", 2);
break;
+
case '\f':
- {
- smart_str_appendl(buf, "\\f", 2);
- }
+ smart_str_appendl(buf, "\\f", 2);
break;
+
case '\n':
- {
- smart_str_appendl(buf, "\\n", 2);
- }
+ smart_str_appendl(buf, "\\n", 2);
break;
+
case '\r':
- {
- smart_str_appendl(buf, "\\r", 2);
- }
+ smart_str_appendl(buf, "\\r", 2);
break;
+
case '\t':
- {
- smart_str_appendl(buf, "\\t", 2);
- }
+ smart_str_appendl(buf, "\\t", 2);
break;
+
case '<':
- {
- if (options & PHP_JSON_HEX_TAG) {
- smart_str_appendl(buf,
"\\u003C", 6);
- } else {
- smart_str_appendc(buf, '<');
- }
+ if (options & PHP_JSON_HEX_TAG) {
+ smart_str_appendl(buf, "\\u003C", 6);
+ } else {
+ smart_str_appendc(buf, '<');
}
break;
+
case '>':
- {
- if (options & PHP_JSON_HEX_TAG) {
- smart_str_appendl(buf,
"\\u003E", 6);
- } else {
- smart_str_appendc(buf, '>');
- }
+ if (options & PHP_JSON_HEX_TAG) {
+ smart_str_appendl(buf, "\\u003E", 6);
+ } else {
+ smart_str_appendc(buf, '>');
}
break;
+
case '&':
- {
- if (options & PHP_JSON_HEX_AMP) {
- smart_str_appendl(buf,
"\\u0026", 6);
- } else {
- smart_str_appendc(buf, '&');
- }
+ if (options & PHP_JSON_HEX_AMP) {
+ smart_str_appendl(buf, "\\u0026", 6);
+ } else {
+ smart_str_appendc(buf, '&');
}
break;
+
case '\'':
- {
- if (options & PHP_JSON_HEX_APOS) {
- smart_str_appendl(buf,
"\\u0027", 6);
- } else {
- smart_str_appendc(buf, '\'');
- }
+ if (options & PHP_JSON_HEX_APOS) {
+ smart_str_appendl(buf, "\\u0027", 6);
+ } else {
+ smart_str_appendc(buf, '\'');
}
break;
+
default:
- {
- if (us >= ' ' && (us & 127) == us)
- {
- smart_str_appendc(buf,
(unsigned char) us);
- }
- else
- {
- smart_str_appendl(buf, "\\u",
2);
- us = REVERSE16(us);
-
- smart_str_appendc(buf,
digits[us & ((1 << 4) - 1)]);
- us >>= 4;
- smart_str_appendc(buf,
digits[us & ((1 << 4) - 1)]);
- us >>= 4;
- smart_str_appendc(buf,
digits[us & ((1 << 4) - 1)]);
- us >>= 4;
- smart_str_appendc(buf,
digits[us & ((1 << 4) - 1)]);
- }
+ if (us >= ' ' && (us & 127) == us) {
+ smart_str_appendc(buf, (unsigned char)
us);
+ } else {
+ smart_str_appendl(buf, "\\u", 2);
+ us = REVERSE16(us);
+
+ smart_str_appendc(buf, digits[us & ((1
<< 4) - 1)]);
+ us >>= 4;
+ smart_str_appendc(buf, digits[us & ((1
<< 4) - 1)]);
+ us >>= 4;
+ smart_str_appendc(buf, digits[us & ((1
<< 4) - 1)]);
+ us >>= 4;
+ smart_str_appendc(buf, digits[us & ((1
<< 4) - 1)]);
}
break;
}
@@ -415,23 +395,24 @@
static void json_encode_r(smart_str *buf, zval *val, int options TSRMLS_DC) /*
{{{ */
{
- switch (Z_TYPE_P(val)) {
+ switch (Z_TYPE_P(val))
+ {
case IS_NULL:
smart_str_appendl(buf, "null", 4);
break;
+
case IS_BOOL:
- if (Z_BVAL_P(val))
- {
+ if (Z_BVAL_P(val)) {
smart_str_appendl(buf, "true", 4);
- }
- else
- {
+ } else {
smart_str_appendl(buf, "false", 5);
}
break;
+
case IS_LONG:
smart_str_append_long(buf, Z_LVAL_P(val));
break;
+
case IS_DOUBLE:
{
char *d = NULL;
@@ -448,14 +429,17 @@
}
}
break;
+
case IS_STRING:
case IS_UNICODE:
json_escape_string(buf, Z_UNIVAL_P(val),
Z_UNILEN_P(val), Z_TYPE_P(val), options TSRMLS_CC);
break;
+
case IS_ARRAY:
case IS_OBJECT:
json_encode_array(buf, &val, options TSRMLS_CC);
break;
+
default:
zend_error(E_WARNING, "[json] (json_encode_r) type is
unsupported, encoded as null.");
smart_str_appendl(buf, "null", 4);
@@ -468,7 +452,7 @@
/* {{{ proto string json_encode(mixed data) U
Returns the JSON representation of a value */
-PHP_FUNCTION(json_encode)
+static PHP_FUNCTION(json_encode)
{
zval *parameter;
smart_str buf = {0};
@@ -492,7 +476,7 @@
/* {{{ proto mixed json_decode(string json [, bool assoc]) U
Decodes the JSON representation into a PHP value */
-PHP_FUNCTION(json_decode)
+static PHP_FUNCTION(json_decode)
{
zstr str;
int str_len, utf16_len;
@@ -505,8 +489,7 @@
return;
}
- if (!str_len)
- {
+ if (!str_len) {
RETURN_NULL();
}
@@ -517,27 +500,25 @@
utf16 = (unsigned short *) safe_emalloc((str_len+1),
sizeof(unsigned short), 0);
utf16_len = utf8_to_utf16(utf16, str.s, str_len);
- if (utf16_len <= 0)
- {
- if (utf16)
- {
+ if (utf16_len <= 0) {
+ if (utf16) {
efree(utf16);
}
-
RETURN_NULL();
}
}
ALLOC_INIT_ZVAL(z);
- if (JSON_parser(z, utf16, utf16_len, assoc TSRMLS_CC))
- {
+ if (JSON_parser(z, utf16, utf16_len, assoc TSRMLS_CC)) {
*return_value = *z;
-
FREE_ZVAL(z);
+
if (str_type == IS_STRING) {
efree(utf16);
}
- } else if (str_type == IS_STRING) {
+ }
+ else if (str_type == IS_STRING)
+ {
double d;
int type;
long p;
@@ -567,7 +548,9 @@
} else {
RETURN_STRINGL(str.s, str_len, 1);
}
- } else {
+ }
+ else
+ {
double d;
int type;
long p;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php