|
@@ -21,6 +21,7 @@
|
|
|
*/
|
|
|
|
|
|
import js.Boot;
|
|
|
+import js.Syntax;
|
|
|
|
|
|
@:keepInit
|
|
|
@:coreApi class Std {
|
|
@@ -48,10 +49,16 @@ import js.Boot;
|
|
|
|
|
|
@:pure
|
|
|
public static function parseInt(x:String):Null<Int> {
|
|
|
- var v = untyped __js__('parseInt({0}, {0} && {0}[0]=="0" && ({0}[1]=="x" || {0}[1]=="X") ? 16 : 10)', x);
|
|
|
- if (untyped __js__("isNaN")(v))
|
|
|
- return null;
|
|
|
- return cast v;
|
|
|
+ if(x != null) {
|
|
|
+ for(i in 0...x.length) {
|
|
|
+ var c = StringTools.fastCodeAt(x, i);
|
|
|
+ if(c <= 8 || (c >= 14 && c != ' '.code && c != '-'.code)) {
|
|
|
+ var v:Int = Syntax.code('parseInt({0}, ({0}[{1}]=="x" || {0}[{1}]=="X") ? 16 : 10)', x, i + 1);
|
|
|
+ return Math.isNaN(v) ? null : v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
public static inline function parseFloat(x:String):Float {
|