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

Side by Side Diff: pkg/fixnum/lib/src/int32.dart

Issue 34223002: Throw FormatException when Int32/Int64.parseRadix() encounters bad digit (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Formatting fix Created 7 years, 2 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
« no previous file with comments | « no previous file | pkg/fixnum/lib/src/int64.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 fixnum; 5 part of fixnum;
6 6
7 /** 7 /**
8 * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1]. 8 * An immutable 32-bit signed integer, in the range [-2^31, 2^31 - 1].
9 * Arithmetic operations may overflow in order to maintain this range. 9 * Arithmetic operations may overflow in order to maintain this range.
10 */ 10 */
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // TODO(rice) - Make this faster by converting several digits at once. 64 // TODO(rice) - Make this faster by converting several digits at once.
65 static Int32 parseRadix(String s, int radix) { 65 static Int32 parseRadix(String s, int radix) {
66 if ((radix <= 1) || (radix > 16)) { 66 if ((radix <= 1) || (radix > 16)) {
67 throw new ArgumentError("Bad radix: $radix"); 67 throw new ArgumentError("Bad radix: $radix");
68 } 68 }
69 Int32 x = ZERO; 69 Int32 x = ZERO;
70 for (int i = 0; i < s.length; i++) { 70 for (int i = 0; i < s.length; i++) {
71 int c = s.codeUnitAt(i); 71 int c = s.codeUnitAt(i);
72 int digit = _decodeDigit(c); 72 int digit = _decodeDigit(c);
73 if (digit < 0 || digit >= radix) { 73 if (digit < 0 || digit >= radix) {
74 throw new Exception("Non-radix code unit: $c"); 74 throw new FormatException("Non-radix code unit: $c");
75 } 75 }
76 x = (x * radix) + digit; 76 x = (x * radix) + digit;
77 } 77 }
78 return x; 78 return x;
79 } 79 }
80 80
81 /** 81 /**
82 * Parses a decimal [String] and returns an [Int32]. 82 * Parses a decimal [String] and returns an [Int32].
83 */ 83 */
84 static Int32 parseInt(String s) => new Int32(int.parse(s)); 84 static Int32 parseInt(String s) => new Int32(int.parse(s));
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 375
376 double toDouble() => _i.toDouble(); 376 double toDouble() => _i.toDouble();
377 int toInt() => _i; 377 int toInt() => _i;
378 Int32 toInt32() => this; 378 Int32 toInt32() => this;
379 Int64 toInt64() => new Int64(_i); 379 Int64 toInt64() => new Int64(_i);
380 380
381 String toString() => _i.toString(); 381 String toString() => _i.toString();
382 String toHexString() => _i.toRadixString(16); 382 String toHexString() => _i.toRadixString(16);
383 String toRadixString(int radix) => _i.toRadixString(radix); 383 String toRadixString(int radix) => _i.toRadixString(radix);
384 } 384 }
OLDNEW
« no previous file with comments | « no previous file | pkg/fixnum/lib/src/int64.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698