Chromium Code Reviews| 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 _handleParseError(String source, | |
| 11 double handleError(String str)) { | |
| 12 if (handleError == null) throw new FormatException(source); | |
| 13 return handleError(source); | |
| 14 } | |
| 15 | |
| 16 static double _native_parse(_OneByteString string) native "Double_parse"; | |
| 17 | |
| 18 static double _parse(var str) { | |
| 19 str = str.trim(); | |
| 20 | |
| 21 if (str.length == 0) return null; | |
| 22 | |
| 23 final ccid = str._cid; | |
| 24 _OneByteString oneByteString; | |
| 25 if ((ccid != _OneByteString._classId)) { | |
| 26 int length = str.length; | |
| 27 var s = _OneByteString._allocate(length); | |
| 28 for (int i = 0; i < length; i++) { | |
| 29 int currentUnit = str[i]; | |
| 30 // All valid trimmed double strings must be ASCII. | |
| 31 if (currentUnit < 128) { | |
| 32 s._setAt(i, currentUnit); | |
| 33 } else { | |
| 34 return null; | |
| 35 } | |
| 36 } | |
| 37 oneByteString = s; | |
| 38 } else { | |
| 39 oneByteString = str; | |
| 40 } | |
| 41 | |
| 42 return _native_parse(oneByteString); | |
| 43 } | |
| 10 | 44 |
| 11 /* patch */ static double parse(String str, | 45 /* patch */ static double parse(String str, |
| 12 [double handleError(String str)]) { | 46 [double handleError(String str)]) { |
| 13 if (handleError == null) return _parse(str); | 47 var result = _parse(str); |
| 14 try { | 48 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
| |
| 15 return _parse(str); | 49 return _handleParseError(str, handleError); |
|
Lasse Reichstein Nielsen
2013/05/21 06:15:06
_handleParseError is only used once, so inline it
| |
| 16 } on FormatException { | |
| 17 return handleError(str); | |
| 18 } | 50 } |
| 51 return result; | |
| 19 } | 52 } |
| 20 } | 53 } |
| OLD | NEW |