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 | 4 |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * Decodes the UTF-16 bytes as an iterable. Thus, the consumer can only convert | 7 * Decodes the UTF-16 bytes as an iterable. Thus, the consumer can only convert |
| 8 * as much of the input as needed. Determines the byte order from the BOM, | 8 * as much of the input as needed. Determines the byte order from the BOM, |
| 9 * or uses big-endian as a default. This method always strips a leading BOM. | 9 * or uses big-endian as a default. This method always strips a leading BOM. |
| 10 * Set the [replacementCodepoint] to null to throw an ArgumentError | 10 * Set the [replacementCodepoint] to null to throw an ArgumentError |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 typedef _ListRangeIterator _CodeUnitsProvider(); | 211 typedef _ListRangeIterator _CodeUnitsProvider(); |
| 212 | 212 |
| 213 /** | 213 /** |
| 214 * Return type of [decodeUtf16AsIterable] and variants. The Iterable type | 214 * Return type of [decodeUtf16AsIterable] and variants. The Iterable type |
| 215 * provides an iterator on demand and the iterator will only translate bytes | 215 * provides an iterator on demand and the iterator will only translate bytes |
| 216 * as requested by the user of the iterator. (Note: results are not cached.) | 216 * as requested by the user of the iterator. (Note: results are not cached.) |
| 217 */ | 217 */ |
| 218 class IterableUtf16Decoder implements Iterable<int> { | 218 class IterableUtf16Decoder extends Iterable<int> { |
|
Ivan Posva
2012/11/26 18:13:01
Please remember by extending rather than implement
floitsch
2012/11/28 14:16:01
Added TODO.
Lasse Reichstein Nielsen
2012/11/28 21:29:35
Is there any way that this could be made cheaper?
| |
| 219 final _CodeUnitsProvider codeunitsProvider; | 219 final _CodeUnitsProvider codeunitsProvider; |
| 220 final int replacementCodepoint; | 220 final int replacementCodepoint; |
| 221 | 221 |
| 222 IterableUtf16Decoder._(this.codeunitsProvider, this.replacementCodepoint); | 222 IterableUtf16Decoder._(this.codeunitsProvider, this.replacementCodepoint); |
| 223 | 223 |
| 224 Utf16CodeUnitDecoder iterator() => | 224 Utf16CodeUnitDecoder iterator() => |
| 225 new Utf16CodeUnitDecoder.fromListRangeIterator(codeunitsProvider(), | 225 new Utf16CodeUnitDecoder.fromListRangeIterator(codeunitsProvider(), |
| 226 replacementCodepoint); | 226 replacementCodepoint); |
| 227 } | 227 } |
| 228 | 228 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 skip(); | 343 skip(); |
| 344 } | 344 } |
| 345 } | 345 } |
| 346 | 346 |
| 347 int decode() { | 347 int decode() { |
| 348 int lo = utf16EncodedBytesIterator.next(); | 348 int lo = utf16EncodedBytesIterator.next(); |
| 349 int hi = utf16EncodedBytesIterator.next(); | 349 int hi = utf16EncodedBytesIterator.next(); |
| 350 return (hi << 8) + lo; | 350 return (hi << 8) + lo; |
| 351 } | 351 } |
| 352 } | 352 } |
| OLD | NEW |