Просмотр исходного кода

Refactor php.ini bool option parsing

Stefan Siegl 9 лет назад
Родитель
Сommit
9275600ac9
1 измененных файлов с 16 добавлено и 32 удалено
  1. 16 32
      v8js.cc

+ 16 - 32
v8js.cc

@@ -48,53 +48,37 @@ static ZEND_INI_MH(v8js_OnUpdateV8Flags) /* {{{ */
 	return SUCCESS;
 }
 
-static ZEND_INI_MH(v8js_OnUpdateUseDate) /* {{{ */
+static bool v8js_ini_to_bool(const char *new_value, uint new_value_length) /* {{{ */
 {
-	bool value;
-	if (new_value_length==2 && strcasecmp("on", new_value)==0) {
-		value = (bool) 1;
-    } else if (new_value_length==3 && strcasecmp("yes", new_value)==0) {
-		value = (bool) 1;
-	} else if (new_value_length==4 && strcasecmp("true", new_value)==0) {
-		value = (bool) 1;
+	if (new_value_length == 2 && strcasecmp("on", new_value) == 0) {
+		return true;
+    } else if (new_value_length == 3 && strcasecmp("yes", new_value) == 0) {
+		return true;
+	} else if (new_value_length == 4 && strcasecmp("true", new_value) == 0) {
+		return true;
 	} else {
-		value = (bool) atoi(new_value);
+		return (bool) atoi(new_value);
 	}
-	V8JSG(use_date) = value;
+}
+/* }}} */
+
+static ZEND_INI_MH(v8js_OnUpdateUseDate) /* {{{ */
+{
+	V8JSG(use_date) = v8js_ini_to_bool(new_value, new_value_length);
 	return SUCCESS;
 }
 /* }}} */
 
 static ZEND_INI_MH(v8js_OnUpdateUseArrayAccess) /* {{{ */
 {
-	bool value;
-	if (new_value_length==2 && strcasecmp("on", new_value)==0) {
-		value = (bool) 1;
-    } else if (new_value_length==3 && strcasecmp("yes", new_value)==0) {
-		value = (bool) 1;
-	} else if (new_value_length==4 && strcasecmp("true", new_value)==0) {
-		value = (bool) 1;
-	} else {
-		value = (bool) atoi(new_value);
-	}
-	V8JSG(use_array_access) = value;
+	V8JSG(use_array_access) = v8js_ini_to_bool(new_value, new_value_length);
 	return SUCCESS;
 }
 /* }}} */
 
 static ZEND_INI_MH(v8js_OnUpdateCompatExceptions) /* {{{ */
 {
-	bool value;
-	if (new_value_length==2 && strcasecmp("on", new_value)==0) {
-		value = (bool) 1;
-    } else if (new_value_length==3 && strcasecmp("yes", new_value)==0) {
-		value = (bool) 1;
-	} else if (new_value_length==4 && strcasecmp("true", new_value)==0) {
-		value = (bool) 1;
-	} else {
-		value = (bool) atoi(new_value);
-	}
-	V8JSG(compat_php_exceptions) = value;
+	V8JSG(compat_php_exceptions) = v8js_ini_to_bool(new_value, new_value_length);
 	return SUCCESS;
 }
 /* }}} */