Index: runtime/lib/double_patch.dart |
diff --git a/runtime/lib/double_patch.dart b/runtime/lib/double_patch.dart |
index e56f45dc74c234ef81628d2bb72d63c120c5c409..63d8bd45921bea93235ff58e9df9ab3e8154aa90 100644 |
--- a/runtime/lib/double_patch.dart |
+++ b/runtime/lib/double_patch.dart |
@@ -6,15 +6,43 @@ |
// VM implementation of double. |
patch class double { |
- static double _parse(String string) native "Double_parse"; |
+ |
+ static double _native_parse(_OneByteString string) native "Double_parse"; |
+ |
+ static double _parse(var str) { |
+ str = str.trim(); |
+ |
+ if (str.length == 0) return null; |
+ |
+ final ccid = str._cid; |
+ _OneByteString oneByteString; |
+ if ((ccid != _OneByteString._classId)) { |
Ivan Posva
2013/05/20 16:00:23
I think it would be OK to have a _ExternalOneByteS
floitsch
2013/05/21 14:39:31
I tried to do this, but _ExternalOneByteString doe
|
+ int length = str.length; |
+ var s = _OneByteString._allocate(length); |
+ for (int i = 0; i < length; i++) { |
+ int currentUnit = str.codeUnitAt(i); |
+ // All valid trimmed double strings must be ASCII. |
+ if (currentUnit < 128) { |
+ s._setAt(i, currentUnit); |
+ } else { |
+ return null; |
+ } |
+ } |
+ oneByteString = s; |
+ } else { |
+ oneByteString = str; |
+ } |
+ |
+ return _native_parse(oneByteString); |
+ } |
/* patch */ static double parse(String str, |
[double handleError(String str)]) { |
- if (handleError == null) return _parse(str); |
- try { |
- return _parse(str); |
- } on FormatException { |
+ var result = _parse(str); |
+ if (result == null) { |
+ if (handleError == null) throw new FormatException(str); |
return handleError(str); |
} |
+ return result; |
} |
} |