| 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 part of dart.utf; | 5 part of dart.utf; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Decodes the UTF-16 bytes as an iterable. Thus, the consumer can only convert | 8 * Decodes the UTF-16 bytes as an iterable. Thus, the consumer can only convert |
| 9 * as much of the input as needed. Determines the byte order from the BOM, | 9 * as much of the input as needed. Determines the byte order from the BOM, |
| 10 * or uses big-endian as a default. This method always strips a leading BOM. | 10 * or uses big-endian as a default. This method always strips a leading BOM. |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 Utf16CodeUnitDecoder get iterator => | 199 Utf16CodeUnitDecoder get iterator => |
| 200 new Utf16CodeUnitDecoder.fromListRangeIterator(codeunitsProvider(), | 200 new Utf16CodeUnitDecoder.fromListRangeIterator(codeunitsProvider(), |
| 201 replacementCodepoint); | 201 replacementCodepoint); |
| 202 } | 202 } |
| 203 | 203 |
| 204 /** | 204 /** |
| 205 * Convert UTF-16 encoded bytes to UTF-16 code units by grouping 1-2 bytes | 205 * Convert UTF-16 encoded bytes to UTF-16 code units by grouping 1-2 bytes |
| 206 * to produce the code unit (0-(2^16)-1). Relies on BOM to determine | 206 * to produce the code unit (0-(2^16)-1). Relies on BOM to determine |
| 207 * endian-ness, and defaults to BE. | 207 * endian-ness, and defaults to BE. |
| 208 */ | 208 */ |
| 209 class Utf16BytesToCodeUnitsDecoder implements _ListRangeIterator { | 209 abstract class Utf16BytesToCodeUnitsDecoder implements _ListRangeIterator { |
| 210 final _ListRangeIterator utf16EncodedBytesIterator; | 210 final _ListRangeIterator utf16EncodedBytesIterator; |
| 211 final int replacementCodepoint; | 211 final int replacementCodepoint; |
| 212 int _current = null; | 212 int _current = null; |
| 213 | 213 |
| 214 Utf16BytesToCodeUnitsDecoder._fromListRangeIterator( | 214 Utf16BytesToCodeUnitsDecoder._fromListRangeIterator( |
| 215 this.utf16EncodedBytesIterator, this.replacementCodepoint); | 215 this.utf16EncodedBytesIterator, this.replacementCodepoint); |
| 216 | 216 |
| 217 factory Utf16BytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, [ | 217 factory Utf16BytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, [ |
| 218 int offset = 0, int length, | 218 int offset = 0, int length, |
| 219 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { | 219 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 328 } |
| 329 | 329 |
| 330 int decode() { | 330 int decode() { |
| 331 utf16EncodedBytesIterator.moveNext(); | 331 utf16EncodedBytesIterator.moveNext(); |
| 332 int lo = utf16EncodedBytesIterator.current; | 332 int lo = utf16EncodedBytesIterator.current; |
| 333 utf16EncodedBytesIterator.moveNext(); | 333 utf16EncodedBytesIterator.moveNext(); |
| 334 int hi = utf16EncodedBytesIterator.current; | 334 int hi = utf16EncodedBytesIterator.current; |
| 335 return (hi << 8) + lo; | 335 return (hi << 8) + lo; |
| 336 } | 336 } |
| 337 } | 337 } |
| OLD | NEW |