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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 void backup([int by = 1]) { | 297 void backup([int by = 1]) { |
298 utf16EncodedBytesIterator.backup(2 * by); | 298 utf16EncodedBytesIterator.backup(2 * by); |
299 } | 299 } |
300 | 300 |
301 int get remaining => (utf16EncodedBytesIterator.remaining + 1) ~/ 2; | 301 int get remaining => (utf16EncodedBytesIterator.remaining + 1) ~/ 2; |
302 | 302 |
303 void skip([int count = 1]) { | 303 void skip([int count = 1]) { |
304 utf16EncodedBytesIterator.skip(2 * count); | 304 utf16EncodedBytesIterator.skip(2 * count); |
305 } | 305 } |
306 | 306 |
307 abstract int decode(); | 307 int decode(); |
308 } | 308 } |
309 | 309 |
310 /** | 310 /** |
311 * Convert UTF-16BE encoded bytes to utf16 code units by grouping 1-2 bytes | 311 * Convert UTF-16BE encoded bytes to utf16 code units by grouping 1-2 bytes |
312 * to produce the code unit (0-(2^16)-1). | 312 * to produce the code unit (0-(2^16)-1). |
313 */ | 313 */ |
314 class Utf16beBytesToCodeUnitsDecoder extends Utf16BytesToCodeUnitsDecoder { | 314 class Utf16beBytesToCodeUnitsDecoder extends Utf16BytesToCodeUnitsDecoder { |
315 Utf16beBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, [ | 315 Utf16beBytesToCodeUnitsDecoder(List<int> utf16EncodedBytes, [ |
316 int offset = 0, int length, bool stripBom = true, | 316 int offset = 0, int length, bool stripBom = true, |
317 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) : | 317 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) : |
(...skipping 25 matching lines...) Expand all 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 |