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 | 9 |
10 static double _native_parse(_OneByteString string) native "Double_parse"; | 10 static double _native_parse(_OneByteString string) native "Double_parse"; |
11 | 11 |
12 static double _parse(var str) { | 12 static double _parse(var str) { |
13 str = str.trim(); | 13 str = str.trim(); |
14 | 14 |
15 if (str.length == 0) return null; | 15 if (str.length == 0) return null; |
16 | 16 |
17 final ccid = str._cid; | 17 final ccid = ClassID.getID(str); |
18 _OneByteString oneByteString; | 18 _OneByteString oneByteString; |
19 // TODO(floitsch): Allow _ExternalOneByteStrings. As of May 2013 they don't | 19 // TODO(floitsch): Allow _ExternalOneByteStrings. As of May 2013 they don't |
20 // have any _classId. | 20 // have any _classId. |
21 if (ccid != _OneByteString._classId) { | 21 if (ccid != _OneByteString._classId) { |
22 int length = str.length; | 22 int length = str.length; |
23 var s = _OneByteString._allocate(length); | 23 var s = _OneByteString._allocate(length); |
24 for (int i = 0; i < length; i++) { | 24 for (int i = 0; i < length; i++) { |
25 int currentUnit = str.codeUnitAt(i); | 25 int currentUnit = str.codeUnitAt(i); |
26 // All valid trimmed double strings must be ASCII. | 26 // All valid trimmed double strings must be ASCII. |
27 if (currentUnit < 128) { | 27 if (currentUnit < 128) { |
(...skipping 13 matching lines...) Expand all Loading... |
41 /* patch */ static double parse(String str, | 41 /* patch */ static double parse(String str, |
42 [double onError(String str)]) { | 42 [double onError(String str)]) { |
43 var result = _parse(str); | 43 var result = _parse(str); |
44 if (result == null) { | 44 if (result == null) { |
45 if (onError == null) throw new FormatException(str); | 45 if (onError == null) throw new FormatException(str); |
46 return onError(str); | 46 return onError(str); |
47 } | 47 } |
48 return result; | 48 return result; |
49 } | 49 } |
50 } | 50 } |
OLD | NEW |