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 /** | 5 /** |
6 * Provide a list of Unicode codepoints for a given string. | 6 * Provide a list of Unicode codepoints for a given string. |
7 */ | 7 */ |
8 List<int> stringToCodepoints(String str) { | 8 List<int> stringToCodepoints(String str) { |
9 List<int> codepoints; | 9 List<int> codepoints; |
10 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js | 10 // TODO _is16BitCodeUnit() is used to work around a bug with dart2js |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 throw new IndexOutOfRangeException(_length); | 225 throw new IndexOutOfRangeException(_length); |
226 } | 226 } |
227 if (_length + _offset > _source.length) { | 227 if (_length + _offset > _source.length) { |
228 throw new IndexOutOfRangeException(_length + _offset); | 228 throw new IndexOutOfRangeException(_length + _offset); |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 _ListRangeIterator iterator() => | 232 _ListRangeIterator iterator() => |
233 new _ListRangeIteratorImpl(_source, _offset, _offset + _length); | 233 new _ListRangeIteratorImpl(_source, _offset, _offset + _length); |
234 | 234 |
235 int get length() => _length; | 235 int get length => _length; |
236 } | 236 } |
237 | 237 |
238 /** | 238 /** |
239 * The _ListRangeIterator provides more capabilities than a standard iterator, | 239 * The _ListRangeIterator provides more capabilities than a standard iterator, |
240 * including the ability to get the current position, count remaining items, | 240 * including the ability to get the current position, count remaining items, |
241 * and move forward/backward within the iterator. | 241 * and move forward/backward within the iterator. |
242 */ | 242 */ |
243 interface _ListRangeIterator extends Iterator<int> { | 243 interface _ListRangeIterator extends Iterator<int> { |
244 bool hasNext(); | 244 bool hasNext(); |
245 int next(); | 245 int next(); |
246 int get position(); | 246 int get position; |
247 void backup([by]); | 247 void backup([by]); |
248 int get remaining(); | 248 int get remaining; |
249 void skip([count]); | 249 void skip([count]); |
250 } | 250 } |
251 | 251 |
252 class _ListRangeIteratorImpl implements _ListRangeIterator { | 252 class _ListRangeIteratorImpl implements _ListRangeIterator { |
253 final List<int> _source; | 253 final List<int> _source; |
254 int _offset; | 254 int _offset; |
255 final int _end; | 255 final int _end; |
256 | 256 |
257 _ListRangeIteratorImpl(this._source, this._offset, this._end); | 257 _ListRangeIteratorImpl(this._source, this._offset, this._end); |
258 | 258 |
259 bool hasNext() => _offset < _end; | 259 bool hasNext() => _offset < _end; |
260 | 260 |
261 int next() => _source[_offset++]; | 261 int next() => _source[_offset++]; |
262 | 262 |
263 int get position() => _offset; | 263 int get position => _offset; |
264 | 264 |
265 void backup([int by = 1]) { | 265 void backup([int by = 1]) { |
266 _offset -= by; | 266 _offset -= by; |
267 } | 267 } |
268 | 268 |
269 int get remaining() => _end - _offset; | 269 int get remaining => _end - _offset; |
270 | 270 |
271 void skip([int count = 1]) { | 271 void skip([int count = 1]) { |
272 _offset += count; | 272 _offset += count; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
OLD | NEW |