Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: runtime/lib/double_patch.dart

Issue 389603002: Add extra information to FormatException. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 _parse(var str) { 13 static double _parse(var str) {
14 int len = str.length; 14 int len = str.length;
15 int start = str._firstNonWhitespace(); 15 int start = str._firstNonWhitespace();
16 if (start == len) return null; // All whitespace. 16 if (start == len) return null; // All whitespace.
17 int end = str._lastNonWhitespace() + 1; 17 int end = str._lastNonWhitespace() + 1;
18 assert(start < end); 18 assert(start < end);
19 19
20 return _nativeParse(str, start, end); 20 return _nativeParse(str, start, end);
21 } 21 }
22 22
23 /* patch */ static double parse(String str, 23 /* patch */ static double parse(String str,
24 [double onError(String str)]) { 24 [double onError(String str)]) {
25 var result = _parse(str); 25 var result = _parse(str);
26 if (result == null) { 26 if (result == null) {
27 if (onError == null) throw new FormatException(str); 27 if (onError == null) throw new FormatException("Invalid double", str);
28 return onError(str); 28 return onError(str);
29 } 29 }
30 return result; 30 return result;
31 } 31 }
32 } 32 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698