Parcourir la source

- php : fixed parsing in Std.int

Franco Ponticelli il y a 15 ans
Parent
commit
e212e94852
2 fichiers modifiés avec 6 ajouts et 4 suppressions
  1. 5 3
      std/php/_std/Std.hx
  2. 1 1
      std/php/io/File.hx

+ 5 - 3
std/php/_std/Std.hx

@@ -38,9 +38,11 @@
 	}
 
 	public static function parseInt( x : String ) : Null<Int> {
-		untyped if (!__php__("is_numeric")(x))
-			return null;
-		else
+		untyped if (!__php__("is_numeric")(x)) {
+			var matches = null;
+			__call__('preg_match', '/\\d+/', x, matches);
+			return __call__("count", matches) == 0 ? null : __call__('intval', matches[0]);
+		} else
 			return x.substr(0, 2).toLowerCase() == "0x" ? __php__("intval(substr($x, 2), 16)") : __php__("intval($x)");
 	}
 

+ 1 - 1
std/php/io/File.hx

@@ -46,7 +46,7 @@ class File {
 		return haxe.io.Bytes.ofString(getContent(path));
 	}
 	
-	public static function putContent( path : String, content : String) : String {
+	public static function putContent( path : String, content : String) : Int {
 		return untyped __call__("file_put_contents", path, content);
 	}