| 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) { | |
| 11 return | |
| 12 (codePoint == 32) || // Space. | |
| 13 ((9 <= codePoint) && (codePoint <= 13)); // CR, LF, TAB, etc. | |
| 14 } | |
| 15 | |
| 16 static int _tryParseSmi(String str) { | 10 static int _tryParseSmi(String str) { |
| 17 if (str.isEmpty) return null; | 11 if (str.isEmpty) return null; |
| 18 var ix = 0; | 12 var ix = 0; |
| 19 var endIx = str.length - 1; | 13 var endIx = str.length - 1; |
| 20 // Find first and last non-whitespace. | 14 // Find first and last non-whitespace. |
| 21 while (ix <= endIx) { | 15 while (ix <= endIx) { |
| 22 if (!_isWhitespace(str.codeUnitAt(ix))) break; | 16 if (!str._isWhitespace(str.codeUnitAt(ix))) break; |
| 23 ix++; | 17 ix++; |
| 24 } | 18 } |
| 25 if (endIx < ix) { | 19 if (endIx < ix) { |
| 26 return null; // Empty. | 20 return null; // Empty. |
| 27 } | 21 } |
| 28 while (endIx > ix) { | 22 while (endIx > ix) { |
| 29 if (!_isWhitespace(str.codeUnitAt(endIx))) break; | 23 if (!str._isWhitespace(str.codeUnitAt(endIx))) break; |
| 30 endIx--; | 24 endIx--; |
| 31 } | 25 } |
| 32 | 26 |
| 33 var isNegative = false; | 27 var isNegative = false; |
| 34 var c = str.codeUnitAt(ix); | 28 var c = str.codeUnitAt(ix); |
| 35 // Check for leading '+' or '-'. | 29 // Check for leading '+' or '-'. |
| 36 if ((c == 0x2b) || (c == 0x2d)) { | 30 if ((c == 0x2b) || (c == 0x2d)) { |
| 37 ix++; | 31 ix++; |
| 38 isNegative = (c == 0x2d); | 32 isNegative = (c == 0x2d); |
| 39 if (ix > endIx) { | 33 if (ix > endIx) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 int digit = digits[code - 0x30]; | 117 int digit = digits[code - 0x30]; |
| 124 if (digit >= radix) return onError(source); | 118 if (digit >= radix) return onError(source); |
| 125 result = result * radix + digit; | 119 result = result * radix + digit; |
| 126 i++; | 120 i++; |
| 127 if (i == source.length) break; | 121 if (i == source.length) break; |
| 128 code = source.codeUnitAt(i); | 122 code = source.codeUnitAt(i); |
| 129 } while (true); | 123 } while (true); |
| 130 return negative ? -result : result; | 124 return negative ? -result : result; |
| 131 } | 125 } |
| 132 } | 126 } |
| OLD | NEW |