scottmac                Tue Mar 17 23:26:02 2009 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/json   json.c 
  Log:
  MFH Replace magic values with a define for json encoding, makes reading it a 
bit easier
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/json/json.c?r1=1.9.2.19.2.18&r2=1.9.2.19.2.19&diff_format=u
Index: php-src/ext/json/json.c
diff -u php-src/ext/json/json.c:1.9.2.19.2.18 
php-src/ext/json/json.c:1.9.2.19.2.19
--- php-src/ext/json/json.c:1.9.2.19.2.18       Tue Mar 17 23:15:40 2009
+++ php-src/ext/json/json.c     Tue Mar 17 23:26:02 2009
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: json.c,v 1.9.2.19.2.18 2009/03/17 23:15:40 scottmac Exp $ */
+/* $Id: json.c,v 1.9.2.19.2.19 2009/03/17 23:26:02 scottmac Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -43,6 +43,9 @@
 #define PHP_JSON_HEX_QUOT      (1<<3)
 #define PHP_JSON_FORCE_OBJECT  (1<<4)
 
+#define PHP_JSON_OUTPUT_ARRAY 0
+#define PHP_JSON_OUTPUT_OBJECT 1
+
 ZEND_DECLARE_MODULE_GLOBALS(json)
 
 /* {{{ arginfo */
@@ -165,7 +168,7 @@
                }
        }
 
-       return 0;
+       return PHP_JSON_OUTPUT_ARRAY;
 }
 /* }}} */
 
@@ -176,10 +179,10 @@
 
        if (Z_TYPE_PP(val) == IS_ARRAY) {
                myht = HASH_OF(*val);
-               r = (options & PHP_JSON_FORCE_OBJECT) ? 1 : 
json_determine_array_type(val TSRMLS_CC);
+               r = (options & PHP_JSON_FORCE_OBJECT) ? PHP_JSON_OUTPUT_OBJECT 
: json_determine_array_type(val TSRMLS_CC);
        } else {
                myht = Z_OBJPROP_PP(val);
-               r = 1;
+               r = PHP_JSON_OUTPUT_OBJECT;
        }
 
        if (myht && myht->nApplyCount > 1) {
@@ -188,7 +191,7 @@
                return;
        }
 
-       if (r == 0) {
+       if (r == PHP_JSON_OUTPUT_ARRAY) {
                smart_str_appendc(buf, '[');
        } else {
                smart_str_appendc(buf, '{');
@@ -218,7 +221,7 @@
                                        tmp_ht->nApplyCount++;
                                }
 
-                               if (r == 0) {
+                               if (r == PHP_JSON_OUTPUT_ARRAY) {
                                        if (need_comma) {
                                                smart_str_appendc(buf, ',');
                                        } else {
@@ -226,7 +229,7 @@
                                        }
  
                                        json_encode_r(buf, *data, options 
TSRMLS_CC);
-                               } else if (r == 1) {
+                               } else if (r == PHP_JSON_OUTPUT_OBJECT) {
                                        if (i == HASH_KEY_IS_STRING) {
                                                if (key[0] == '\0' && 
Z_TYPE_PP(val) == IS_OBJECT) {
                                                        /* Skip protected and 
private members. */
@@ -269,7 +272,7 @@
                }
        }
 
-       if (r == 0) {
+       if (r == PHP_JSON_OUTPUT_ARRAY) {
                smart_str_appendc(buf, ']');
        } else {
                smart_str_appendc(buf, '}');



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to