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

Unified Diff: tool/input_sdk/lib/core/num.dart

Issue 1950133008: Update number parsing. (Closed) Base URL: https://github.com/dart-lang/dev_compiler@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tool/input_sdk/lib/core/list.dart ('k') | tool/input_sdk/private/js_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tool/input_sdk/lib/core/num.dart
diff --git a/tool/input_sdk/lib/core/num.dart b/tool/input_sdk/lib/core/num.dart
index 2fc4234b60f83bf656d0842935cfaf25db487cc8..00e7a45578d54cd81e591317400f08808e5c8d02 100644
--- a/tool/input_sdk/lib/core/num.dart
+++ b/tool/input_sdk/lib/core/num.dart
@@ -439,24 +439,15 @@ abstract class num implements Comparable<num> {
static num parse(String input, [num onError(String input)]) {
String source = input.trim();
// TODO(lrn): Optimize to detect format and result type in one check.
- _parseError = false;
- num result = int.parse(source, onError: _onParseErrorInt);
- if (!_parseError) return result;
- _parseError = false;
- result = double.parse(source, _onParseErrorDouble);
- if (!_parseError) return result;
+ num result = int.parse(source, onError: _returnIntNull);
+ if (result != null) return result;
+ result = double.parse(source, _returnDoubleNull);
+ if (result != null) return result;
if (onError == null) throw new FormatException(input);
return onError(input);
}
/** Helper functions for [parse]. */
- static bool _parseError = false;
- static int _onParseErrorInt(String _) {
- _parseError = true;
- return 0;
- }
- static double _onParseErrorDouble(String _) {
- _parseError = true;
- return 0.0;
- }
+ static int _returnIntNull(String _) => null;
+ static double _returnDoubleNull(String _) => null;
}
« no previous file with comments | « tool/input_sdk/lib/core/list.dart ('k') | tool/input_sdk/private/js_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698