{
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;
}
/* }}} */
+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) /* {{{ */
{
}
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;
}
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;
}
/* }}} */
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));