| 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 _nativeParse(String str, | 10 static double _nativeParse(String str, |
| 11 int start, int end) native "Double_parse"; | 11 int start, int end) native "Double_parse"; |
| 12 | 12 |
| 13 static double _tryParseDouble(var str, var start, var end) { | 13 static double _tryParseDouble(var str, var start, var end) { |
| 14 assert(start < end); | 14 assert(start < end); |
| 15 const int _DOT = 0x2e; // '.' | 15 const int _DOT = 0x2e; // '.' |
| 16 const int _ZERO = 0x30; // '0' | 16 const int _ZERO = 0x30; // '0' |
| 17 const int _MINUS = 0x2d; // '-' | 17 const int _MINUS = 0x2d; // '-' |
| 18 const int _N = 0x4e; // 'N' | 18 const int _N = 0x4e; // 'N' |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 int len = str.length; | 94 int len = str.length; |
| 95 int start = str._firstNonWhitespace(); | 95 int start = str._firstNonWhitespace(); |
| 96 if (start == len) return null; // All whitespace. | 96 if (start == len) return null; // All whitespace. |
| 97 int end = str._lastNonWhitespace() + 1; | 97 int end = str._lastNonWhitespace() + 1; |
| 98 assert(start < end); | 98 assert(start < end); |
| 99 var result = _tryParseDouble(str, start, end); | 99 var result = _tryParseDouble(str, start, end); |
| 100 if (result != null) return result; | 100 if (result != null) return result; |
| 101 return _nativeParse(str, start, end); | 101 return _nativeParse(str, start, end); |
| 102 } | 102 } |
| 103 | 103 |
| 104 /* patch */ static double parse(String str, | 104 /* @patch */ static double parse(String str, |
| 105 [double onError(String str)]) { | 105 [double onError(String str)]) { |
| 106 var result = _parse(str); | 106 var result = _parse(str); |
| 107 if (result == null) { | 107 if (result == null) { |
| 108 if (onError == null) throw new FormatException("Invalid double", str); | 108 if (onError == null) throw new FormatException("Invalid double", str); |
| 109 return onError(str); | 109 return onError(str); |
| 110 } | 110 } |
| 111 return result; | 111 return result; |
| 112 } | 112 } |
| 113 } | 113 } |
| OLD | NEW |