Chromium Code Reviews| 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 _isWhitespace(int codePoint) { | 10 static bool _isWhitespace(int codePoint) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 if (onError == null) { | 80 if (onError == null) { |
| 81 throw new FormatException(source); | 81 throw new FormatException(source); |
| 82 } | 82 } |
| 83 return onError(source); | 83 return onError(source); |
| 84 } | 84 } |
| 85 return result; | 85 return result; |
| 86 } | 86 } |
| 87 return _slowParse(source, radix, onError); | 87 return _slowParse(source, radix, onError); |
| 88 } | 88 } |
| 89 | 89 |
| 90 /* patch */ const factory int.env(String name, int defaultValue) | |
|
bakster
2013/09/27 07:44:39
[int defaultValue = 0]
Ivan Posva
2013/09/27 21:05:06
See comment in string.dart.
| |
| 91 native "Integer_env"; | |
| 92 | |
| 90 static int _slowParse(String source, int radix, int onError(String str)) { | 93 static int _slowParse(String source, int radix, int onError(String str)) { |
| 91 if (source is! String) throw new ArgumentError(source); | 94 if (source is! String) throw new ArgumentError(source); |
| 92 if (radix is! int) throw new ArgumentError("Radix is not an integer"); | 95 if (radix is! int) throw new ArgumentError("Radix is not an integer"); |
| 93 if (radix < 2 || radix > 36) { | 96 if (radix < 2 || radix > 36) { |
| 94 throw new RangeError("Radix $radix not in range 2..36"); | 97 throw new RangeError("Radix $radix not in range 2..36"); |
| 95 } | 98 } |
| 96 if (onError == null) { | 99 if (onError == null) { |
| 97 onError = _throwFormatException; | 100 onError = _throwFormatException; |
| 98 } | 101 } |
| 99 // Remove leading and trailing white space. | 102 // Remove leading and trailing white space. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 127 int digit = digits[code - 0x30]; | 130 int digit = digits[code - 0x30]; |
| 128 if (digit >= radix) return onError(source); | 131 if (digit >= radix) return onError(source); |
| 129 result = result * radix + digit; | 132 result = result * radix + digit; |
| 130 i++; | 133 i++; |
| 131 if (i == source.length) break; | 134 if (i == source.length) break; |
| 132 code = source.codeUnitAt(i); | 135 code = source.codeUnitAt(i); |
| 133 } while (true); | 136 } while (true); |
| 134 return negative ? -result : result; | 137 return negative ? -result : result; |
| 135 } | 138 } |
| 136 } | 139 } |
| OLD | NEW |