]> granicus.if.org Git - php/commitdiff
Separate duplicated code into a zend_ini_parse_bool() function.
authorDmitry Stogov <dmitry@zend.com>
Mon, 5 Mar 2018 08:51:58 +0000 (11:51 +0300)
committerDmitry Stogov <dmitry@zend.com>
Mon, 5 Mar 2018 08:51:58 +0000 (11:51 +0300)
Zend/zend.c
Zend/zend_ini.c
Zend/zend_ini.h

index d8ed9bcd35111c98251b125aa0b71b90d48515a2..09b7454468d91f5a9b2ed7c642745eb38755dd8c 100644 (file)
@@ -103,16 +103,7 @@ static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */
 {
        zend_bool val;
 
-       if (ZSTR_LEN(new_value) == 2 && strcasecmp("on", ZSTR_VAL(new_value)) == 0) {
-               val = 1;
-       } else if (ZSTR_LEN(new_value) == 3 && strcasecmp("yes", ZSTR_VAL(new_value)) == 0) {
-               val = 1;
-       }else if (ZSTR_LEN(new_value) == 4 && strcasecmp("true", ZSTR_VAL(new_value)) == 0) {
-               val = 1;
-       } else {
-               val = (zend_bool) atoi(ZSTR_VAL(new_value));
-       }
-
+       val = zend_ini_parse_bool(new_value);
        gc_enable(val);
 
        return SUCCESS;
index c488eda6493ed3f9708048fbeeae6604d9aeaac1..70db810819c4a90478d1b84e2d470243da532a21 100644 (file)
@@ -509,6 +509,17 @@ ZEND_API zend_string *zend_ini_get_value(zend_string *name) /* {{{ */
 }
 /* }}} */
 
+ZEND_API zend_bool zend_ini_parse_bool(zend_string *str)
+{
+       if ((ZSTR_LEN(str) == 4 && strcasecmp(ZSTR_VAL(str), "true") == 0)
+         || (ZSTR_LEN(str) == 3 && strcasecmp(ZSTR_VAL(str), "yes") == 0)
+         || (ZSTR_LEN(str) == 2 && strcasecmp(ZSTR_VAL(str), "on") == 0)) {
+               return 1;
+       } else {
+               return atoi(ZSTR_VAL(str)) != 0;
+       }
+}
+
 #if TONY_20070307
 static void zend_ini_displayer_cb(zend_ini_entry *ini_entry, int type) /* {{{ */
 {
@@ -563,15 +574,7 @@ ZEND_INI_DISP(zend_ini_boolean_displayer_cb) /* {{{ */
        }
 
        if (tmp_value) {
-               if (ZSTR_LEN(tmp_value) == 4 && strcasecmp(ZSTR_VAL(tmp_value), "true") == 0) {
-                       value = 1;
-               } else if (ZSTR_LEN(tmp_value) == 3 && strcasecmp(ZSTR_VAL(tmp_value), "yes") == 0) {
-                       value = 1;
-               } else if (ZSTR_LEN(tmp_value) == 2 && strcasecmp(ZSTR_VAL(tmp_value), "on") == 0) {
-                       value = 1;
-               } else {
-                       value = atoi(ZSTR_VAL(tmp_value));
-               }
+               value = zend_ini_parse_bool(tmp_value);
        } else {
                value = 0;
        }
@@ -647,18 +650,7 @@ ZEND_API ZEND_INI_MH(OnUpdateBool) /* {{{ */
 
        p = (zend_bool *) (base+(size_t) mh_arg1);
 
-       if (ZSTR_LEN(new_value) == 2 && strcasecmp("on", ZSTR_VAL(new_value)) == 0) {
-               *p = (zend_bool) 1;
-       }
-       else if (ZSTR_LEN(new_value) == 3 && strcasecmp("yes", ZSTR_VAL(new_value)) == 0) {
-               *p = (zend_bool) 1;
-       }
-       else if (ZSTR_LEN(new_value) == 4 && strcasecmp("true", ZSTR_VAL(new_value)) == 0) {
-               *p = (zend_bool) 1;
-       }
-       else {
-               *p = (zend_bool) atoi(ZSTR_VAL(new_value));
-       }
+       *p = zend_ini_parse_bool(new_value);
        return SUCCESS;
 }
 /* }}} */
index a7e1448cf4b9409c9c33e9c07b41808f24ed6335..e1fe568ca093d9f3b93f8a41b18c026cda6a2906 100644 (file)
@@ -88,6 +88,7 @@ ZEND_API double zend_ini_double(char *name, size_t name_length, int orig);
 ZEND_API char *zend_ini_string(char *name, size_t name_length, int orig);
 ZEND_API char *zend_ini_string_ex(char *name, size_t name_length, int orig, zend_bool *exists);
 ZEND_API zend_string *zend_ini_get_value(zend_string *name);
+ZEND_API zend_bool zend_ini_parse_bool(zend_string *str);
 
 ZEND_API int zend_ini_register_displayer(char *name, uint32_t name_length, void (*displayer)(zend_ini_entry *ini_entry, int type));