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

Side by Side Diff: sdk/lib/core/num.dart

Issue 1895473004: Make dart:core strong-mode clean. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments. Created 4 years, 8 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
« no previous file with comments | « sdk/lib/core/iterable.dart ('k') | sdk/lib/core/uri.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4
5 part of dart.core; 5 part of dart.core;
6 6
7 /** 7 /**
8 * An integer or floating-point number. 8 * An integer or floating-point number.
9 * 9 *
10 * It is a compile-time error for any type other than [int] or [double] 10 * It is a compile-time error for any type other than [int] or [double]
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 * If no [onError] is supplied, it defaults to a function that throws a 432 * If no [onError] is supplied, it defaults to a function that throws a
433 * [FormatException]. 433 * [FormatException].
434 * 434 *
435 * For any number `n`, this function satisfies 435 * For any number `n`, this function satisfies
436 * `identical(n, num.parse(n.toString()))` (except when `n` is a NaN `double` 436 * `identical(n, num.parse(n.toString()))` (except when `n` is a NaN `double`
437 * with a payload). 437 * with a payload).
438 */ 438 */
439 static num parse(String input, [num onError(String input)]) { 439 static num parse(String input, [num onError(String input)]) {
440 String source = input.trim(); 440 String source = input.trim();
441 // TODO(lrn): Optimize to detect format and result type in one check. 441 // TODO(lrn): Optimize to detect format and result type in one check.
442 num result = int.parse(source, onError: _returnNull); 442 num result = int.parse(source, onError: _returnIntNull);
443 if (result != null) return result; 443 if (result != null) return result;
444 result = double.parse(source, _returnNull); 444 result = double.parse(source, _returnDoubleNull);
445 if (result != null) return result; 445 if (result != null) return result;
446 if (onError == null) throw new FormatException(input); 446 if (onError == null) throw new FormatException(input);
447 return onError(input); 447 return onError(input);
448 } 448 }
449 449
450 /** Helper function for [parse]. */ 450 /** Helper functions for [parse]. */
451 static _returnNull(_) => null; 451 static int _returnIntNull(String _) => null;
452 static double _returnDoubleNull(String _) => null;
452 } 453 }
OLDNEW
« no previous file with comments | « sdk/lib/core/iterable.dart ('k') | sdk/lib/core/uri.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698