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

[php] fix Std.parseInt() for haxedecimals on PHP < 7.1

Alexander Kuzmenko 8 лет назад
Родитель
Сommit
cf562f00f3
1 измененных файлов с 10 добавлено и 14 удалено
  1. 10 14
      std/php/_std/Std.hx

+ 10 - 14
std/php/_std/Std.hx

@@ -41,21 +41,17 @@
 	}
 
 	public static function parseInt( x : String ) : Null<Int> {
-		if (untyped __call__("is_numeric", x)) {
-			return untyped __call__("intval", x, 10);
+		x = untyped __call__("ltrim", x);
+		var firstCharIndex = (x.charAt(0) == '-' ? 1 : 0);
+		var firstCharCode = x.charCodeAt(firstCharIndex);
+		if (!isDigitCode(firstCharCode)) {
+			return null;
+		}
+		var secondChar = x.charAt(firstCharIndex + 1);
+		if (secondChar == 'x' || secondChar == 'X') {
+			return untyped __call__("intval", x, 0);
 		} else {
-			x = untyped __call__("ltrim", x);
-			var firstCharIndex = (x.charAt(0) == '-' ? 1 : 0);
-			var firstCharCode = x.charCodeAt(firstCharIndex);
-			if (!isDigitCode(firstCharCode)) {
-				return null;
-			}
-			var secondChar = x.charAt(firstCharIndex + 1);
-			if (secondChar == 'x' || secondChar == 'X') {
-				return untyped __call__("intval", x, 0);
-			} else {
-				return untyped __call__("intval", x, 10);
-			}
+			return untyped __call__("intval", x, 10);
 		}
 	}