OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Dart core library. | 4 // Dart core library. |
5 | 5 |
6 // VM implementation of double. | 6 // VM implementation of double. |
7 | 7 |
8 patch class double { | 8 patch class double { |
9 static double _parse(String string) native "Double_parse"; | 9 |
10 static double _native_parse(_OneByteString string) native "Double_parse"; | |
11 | |
12 static double _parse(var str) { | |
13 str = str.trim(); | |
14 | |
15 if (str.length == 0) return null; | |
16 | |
17 final ccid = str._cid; | |
18 _OneByteString oneByteString; | |
19 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
| |
20 int length = str.length; | |
21 var s = _OneByteString._allocate(length); | |
22 for (int i = 0; i < length; i++) { | |
23 int currentUnit = str.codeUnitAt(i); | |
24 // All valid trimmed double strings must be ASCII. | |
25 if (currentUnit < 128) { | |
26 s._setAt(i, currentUnit); | |
27 } else { | |
28 return null; | |
29 } | |
30 } | |
31 oneByteString = s; | |
32 } else { | |
33 oneByteString = str; | |
34 } | |
35 | |
36 return _native_parse(oneByteString); | |
37 } | |
10 | 38 |
11 /* patch */ static double parse(String str, | 39 /* patch */ static double parse(String str, |
12 [double handleError(String str)]) { | 40 [double handleError(String str)]) { |
13 if (handleError == null) return _parse(str); | 41 var result = _parse(str); |
14 try { | 42 if (result == null) { |
15 return _parse(str); | 43 if (handleError == null) throw new FormatException(str); |
16 } on FormatException { | |
17 return handleError(str); | 44 return handleError(str); |
18 } | 45 } |
46 return result; | |
19 } | 47 } |
20 } | 48 } |
OLD | NEW |