| 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 | 4 |
| 5 library utf.list_range; | 5 library utf.list_range; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * _ListRange in an internal type used to create a lightweight Interable on a | 10 * _ListRange in an internal type used to create a lightweight Interable on a |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * The ListRangeIterator provides more capabilities than a standard iterator, | 43 * The ListRangeIterator provides more capabilities than a standard iterator, |
| 44 * including the ability to get the current position, count remaining items, | 44 * including the ability to get the current position, count remaining items, |
| 45 * and move forward/backward within the iterator. | 45 * and move forward/backward within the iterator. |
| 46 */ | 46 */ |
| 47 abstract class ListRangeIterator implements Iterator<int> { | 47 abstract class ListRangeIterator implements Iterator<int> { |
| 48 bool moveNext(); | 48 bool moveNext(); |
| 49 int get current; | 49 int get current; |
| 50 int get position; | 50 int get position; |
| 51 void backup([by]); | 51 void backup([int by]); |
| 52 int get remaining; | 52 int get remaining; |
| 53 void skip([count]); | 53 void skip([int count]); |
| 54 } | 54 } |
| 55 | 55 |
| 56 class _ListRangeIteratorImpl implements ListRangeIterator { | 56 class _ListRangeIteratorImpl implements ListRangeIterator { |
| 57 final List<int> _source; | 57 final List<int> _source; |
| 58 int _offset; | 58 int _offset; |
| 59 final int _end; | 59 final int _end; |
| 60 | 60 |
| 61 _ListRangeIteratorImpl(this._source, int offset, this._end) | 61 _ListRangeIteratorImpl(this._source, int offset, this._end) |
| 62 : _offset = offset - 1; | 62 : _offset = offset - 1; |
| 63 | 63 |
| 64 int get current => _source[_offset]; | 64 int get current => _source[_offset]; |
| 65 | 65 |
| 66 bool moveNext() => ++_offset < _end; | 66 bool moveNext() => ++_offset < _end; |
| 67 | 67 |
| 68 int get position => _offset; | 68 int get position => _offset; |
| 69 | 69 |
| 70 void backup([int by = 1]) { | 70 void backup([int by = 1]) { |
| 71 _offset -= by; | 71 _offset -= by; |
| 72 } | 72 } |
| 73 | 73 |
| 74 int get remaining => _end - _offset - 1; | 74 int get remaining => _end - _offset - 1; |
| 75 | 75 |
| 76 void skip([int count = 1]) { | 76 void skip([int count = 1]) { |
| 77 _offset += count; | 77 _offset += count; |
| 78 } | 78 } |
| 79 } | 79 } |
| OLD | NEW |