| 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 int. | 6 // VM implementation of int. |
| 7 | 7 |
| 8 patch class int { | 8 patch class int { |
| 9 static int _parse(String str) native "Integer_parse"; | 9 static int _parse(String str) native "Integer_parse"; |
| 10 | 10 |
| 11 static void _throwFormatException(String source) { | 11 static int _throwFormatException(String source) { |
| 12 throw new FormatException(source); | 12 throw new FormatException(source); |
| 13 } | 13 } |
| 14 | 14 |
| 15 /* patch */ static int parse(String source, | 15 /* patch */ static int parse(String source, |
| 16 { int radix, | 16 { int radix, |
| 17 int onError(String str) }) { | 17 int onError(String str) }) { |
| 18 if (source is! String) throw new ArgumentError(source); | 18 if (source is! String) throw new ArgumentError(source); |
| 19 if (radix == null) { | 19 if (radix == null) { |
| 20 if (onError == null) return _parse(source); | 20 if (onError == null) return _parse(source); |
| 21 try { | 21 try { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 int digit = digits[code - 0x30]; | 62 int digit = digits[code - 0x30]; |
| 63 if (digit >= radix) return onError(source); | 63 if (digit >= radix) return onError(source); |
| 64 result = result * radix + digit; | 64 result = result * radix + digit; |
| 65 i++; | 65 i++; |
| 66 if (i == source.length) break; | 66 if (i == source.length) break; |
| 67 code = source.charCodeAt(i); | 67 code = source.charCodeAt(i); |
| 68 } while (true); | 68 } while (true); |
| 69 return negative ? -result : result; | 69 return negative ? -result : result; |
| 70 } | 70 } |
| 71 } | 71 } |
| OLD | NEW |