| 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 * Decodes the UTF-32 bytes as an iterable. Thus, the consumer can only convert | 6 * Decodes the UTF-32 bytes as an iterable. Thus, the consumer can only convert |
| 7 * as much of the input as needed. Determines the byte order from the BOM, | 7 * as much of the input as needed. Determines the byte order from the BOM, |
| 8 * or uses big-endian as a default. This method always strips a leading BOM. | 8 * or uses big-endian as a default. This method always strips a leading BOM. |
| 9 * Set the replacementCharacter to null to throw an IllegalArgumentException | 9 * Set the replacementCharacter to null to throw an IllegalArgumentException |
| 10 * rather than replace the bad value. | 10 * rather than replace the bad value. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 final Function codeunitsProvider; | 182 final Function codeunitsProvider; |
| 183 | 183 |
| 184 IterableUtf32Decoder._(Function this.codeunitsProvider); | 184 IterableUtf32Decoder._(Function this.codeunitsProvider); |
| 185 | 185 |
| 186 Utf32BytesDecoder iterator() => codeunitsProvider(); | 186 Utf32BytesDecoder iterator() => codeunitsProvider(); |
| 187 } | 187 } |
| 188 | 188 |
| 189 /** | 189 /** |
| 190 * Abstrace parent class converts encoded bytes to codepoints. | 190 * Abstrace parent class converts encoded bytes to codepoints. |
| 191 */ | 191 */ |
| 192 class Utf32BytesDecoder implements _ListRangeIterator<int> { | 192 class Utf32BytesDecoder implements _ListRangeIterator { |
| 193 final _ListRangeIterator<int> utf32EncodedBytesIterator; | 193 final _ListRangeIterator utf32EncodedBytesIterator; |
| 194 final int replacementCodepoint; | 194 final int replacementCodepoint; |
| 195 | 195 |
| 196 Utf32BytesDecoder._fromListRangeIterator( | 196 Utf32BytesDecoder._fromListRangeIterator( |
| 197 _ListRangeIterator<int> this.utf32EncodedBytesIterator, | 197 _ListRangeIterator this.utf32EncodedBytesIterator, |
| 198 int this.replacementCodepoint); | 198 int this.replacementCodepoint); |
| 199 | 199 |
| 200 factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [ | 200 factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [ |
| 201 int offset = 0, int length, | 201 int offset = 0, int length, |
| 202 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { | 202 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { |
| 203 if (length == null) { | 203 if (length == null) { |
| 204 length = utf32EncodedBytes.length - offset; | 204 length = utf32EncodedBytes.length - offset; |
| 205 } | 205 } |
| 206 if (hasUtf32beBom(utf32EncodedBytes, offset, length)) { | 206 if (hasUtf32beBom(utf32EncodedBytes, offset, length)) { |
| 207 return new Utf32beBytesDecoder(utf32EncodedBytes, offset + 4, length - 4, | 207 return new Utf32beBytesDecoder(utf32EncodedBytes, offset + 4, length - 4, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 value += (utf32EncodedBytesIterator.next() << 24); | 309 value += (utf32EncodedBytesIterator.next() << 24); |
| 310 return value; | 310 return value; |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 bool _validCodepoint(int codepoint) { | 314 bool _validCodepoint(int codepoint) { |
| 315 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || | 315 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || |
| 316 (codepoint > UNICODE_UTF16_RESERVED_HI && | 316 (codepoint > UNICODE_UTF16_RESERVED_HI && |
| 317 codepoint < UNICODE_VALID_RANGE_MAX); | 317 codepoint < UNICODE_VALID_RANGE_MAX); |
| 318 } | 318 } |
| OLD | NEW |