| 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 | 9 |
| 10 static bool is64Bit() => 1 << 32 is _Smi; | 10 static bool is64Bit() => 1 << 32 is _Smi; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 static int _native_parse(String str) native "Integer_parse"; | 56 static int _native_parse(String str) native "Integer_parse"; |
| 57 | 57 |
| 58 static int _throwFormatException(String source, int position) { | 58 static int _throwFormatException(String source, int position) { |
| 59 throw new FormatException("", source, position); | 59 throw new FormatException("", source, position); |
| 60 } | 60 } |
| 61 | 61 |
| 62 /* patch */ static int parse(String source, | 62 /* patch */ static int parse(String source, |
| 63 { int radix, | 63 { int radix, |
| 64 int onError(String str) }) { | 64 int onError(String str) }) { |
| 65 if (identical(source, null)) throw new ArgumentError(source); | 65 if (source == null) throw new ArgumentError(source); |
| 66 if (radix == null) { | 66 if (radix == null) { |
| 67 int result; | 67 int result; |
| 68 if (source.isNotEmpty) result = _parse(source); | 68 if (source.isNotEmpty) result = _parse(source); |
| 69 if (result == null) { | 69 if (result == null) { |
| 70 if (onError == null) { | 70 if (onError == null) { |
| 71 throw new FormatException("", source); | 71 throw new FormatException("", source); |
| 72 } | 72 } |
| 73 return onError(source); | 73 return onError(source); |
| 74 } | 74 } |
| 75 return result; | 75 return result; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 int digit = digits[code - 0x30]; | 122 int digit = digits[code - 0x30]; |
| 123 if (digit >= radix) return onError(source); | 123 if (digit >= radix) return onError(source); |
| 124 result = result * radix + digit; | 124 result = result * radix + digit; |
| 125 i++; | 125 i++; |
| 126 if (i == end) break; | 126 if (i == end) break; |
| 127 code = source.codeUnitAt(i); | 127 code = source.codeUnitAt(i); |
| 128 } while (true); | 128 } while (true); |
| 129 return negative ? -result : result; | 129 return negative ? -result : result; |
| 130 } | 130 } |
| 131 } | 131 } |
| OLD | NEW |