Sfoglia il codice sorgente

[java/cs] Fix parseFloat tests from #4132 and on java/cs

See #4051
Cauê Waneck 10 anni fa
parent
commit
f19ddc6671
2 ha cambiato i file con 27 aggiunte e 28 eliminazioni
  1. 13 14
      std/cs/_std/Std.hx
  2. 14 14
      std/java/_std/Std.hx

+ 13 - 14
std/cs/_std/Std.hx

@@ -134,7 +134,8 @@ import cs.internal.Exceptions;
 	public static function parseFloat( x : String ) : Float {
 		if (x == null) return Math.NaN;
 		x = StringTools.ltrim(x);
-		var found = false, isHex = false, hasDot = false, hasE = false, hasNeg = false, hasESign = false;
+		var found = false, hasDot = false, hasSign = false,
+		    hasE = false, hasESign = false, hasEData = false;
 		var i = -1;
 		inline function getch(i:Int):Int return cast ((untyped x : cs.system.String)[i]);
 
@@ -143,32 +144,30 @@ import cs.internal.Exceptions;
 			var chr = getch(i);
 			if (chr >= '0'.code && chr <= '9'.code)
 			{
-				if ( !found && chr == '0'.code && (i+1) < x.length )
+				if (hasE)
 				{
-					var next = getch(i+1);
-					if (next == 'x'.code || next == 'X'.code)
-					{
-						isHex = true;
-						i++;
-					}
+					hasEData = true;
 				}
 				found = true;
 			} else switch (chr) {
-				case 'a'.code | 'b'.code | 'c'.code | 'd'.code | 'e'.code | 'f'.code
-				   | 'A'.code | 'B'.code | 'C'.code | 'D'.code | 'E'.code | 'F'.code if (isHex):
-					//do nothing - it's alright
 				case 'e'.code | 'E'.code if(!hasE):
 					hasE = true;
 				case '.'.code if (!hasDot):
 					hasDot = true;
-				case '-'.code if (!found && !hasNeg):
-					hasNeg = true;
-				case '-'.code | '+'.code if (found && !hasESign && hasE):
+				case '-'.code, '+'.code if (!found && !hasSign):
+					hasSign = true;
+				case '-'.code | '+'.code if (found && !hasESign && hasE && !hasEData):
 					hasESign = true;
 				case _:
 					break;
 			}
 		}
+		if (hasE && !hasEData)
+		{
+			i--;
+			if (hasESign)
+				i--;
+		}
 		if (i != x.length)
 		{
 			x = x.substr(0,i);

+ 14 - 14
std/java/_std/Std.hx

@@ -138,7 +138,8 @@ import java.internal.Exceptions;
 	public static function parseFloat( x : String ) : Float {
 		if (x == null) return Math.NaN;
 		x = StringTools.ltrim(x);
-		var found = false, isHex = false, hasDot = false, hasE = false, hasNeg = false, hasESign = false;
+		var found = false, hasDot = false, hasSign = false,
+		    hasE = false, hasESign = false, hasEData = false;
 		var i = -1;
 		inline function getch(i:Int):Int return cast (untyped x._charAt(i) : java.StdTypes.Char16);
 
@@ -147,32 +148,31 @@ import java.internal.Exceptions;
 			var chr = getch(i);
 			if (chr >= '0'.code && chr <= '9'.code)
 			{
-				if ( !found && chr == '0'.code && (i+1) < x.length )
+				if (hasE)
 				{
-					var next = getch(i+1);
-					if (next == 'x'.code || next == 'X'.code)
-					{
-						isHex = true;
-						i++;
-					}
+					hasEData = true;
 				}
 				found = true;
 			} else switch (chr) {
-				case 'a'.code | 'b'.code | 'c'.code | 'd'.code | 'e'.code | 'f'.code
-				   | 'A'.code | 'B'.code | 'C'.code | 'D'.code | 'E'.code | 'F'.code if (isHex):
-					//do nothing - it's alright
 				case 'e'.code | 'E'.code if(!hasE):
 					hasE = true;
 				case '.'.code if (!hasDot):
 					hasDot = true;
-				case '-'.code if (!found && !hasNeg):
-					hasNeg = true;
-				case '-'.code | '+'.code if (found && !hasESign && hasE):
+				case '-'.code, '+'.code if (!found && !hasSign):
+					hasSign = true;
+				case '-'.code | '+'.code if (found && !hasESign && hasE && !hasEData):
 					hasESign = true;
 				case _:
 					break;
 			}
 		}
+		if (hasE && !hasEData)
+		{
+			i--;
+			if (hasESign)
+				i--;
+		}
+
 		if (i != x.length)
 		{
 			x = x.substr(0,i);