Index: runtime/lib/double_patch.dart |
diff --git a/runtime/lib/double_patch.dart b/runtime/lib/double_patch.dart |
index e56f45dc74c234ef81628d2bb72d63c120c5c409..9fb1157df410d0d2a700924242a5aa050a8a723e 100644 |
--- a/runtime/lib/double_patch.dart |
+++ b/runtime/lib/double_patch.dart |
@@ -6,15 +6,48 @@ |
// VM implementation of double. |
patch class double { |
- static double _parse(String string) native "Double_parse"; |
+ |
+ static double _handleParseError(String source, |
+ double handleError(String str)) { |
+ if (handleError == null) throw new FormatException(source); |
+ return handleError(source); |
+ } |
+ |
+ 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)) { |
+ int length = str.length; |
+ var s = _OneByteString._allocate(length); |
+ for (int i = 0; i < length; i++) { |
+ int currentUnit = str[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 { |
- return handleError(str); |
+ var result = _parse(str); |
+ if (result == null) { |
srdjan
2013/05/17 23:19:06
What if handleError is NULL
floitsch
2013/05/20 13:15:29
First line in _handleParseError: it throws a Forma
|
+ return _handleParseError(str, handleError); |
Lasse Reichstein Nielsen
2013/05/21 06:15:06
_handleParseError is only used once, so inline it
|
} |
+ return result; |
} |
} |