| 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 ArgumentError | 9 * Set the replacementCharacter to null to throw an ArgumentError |
| 10 * rather than replace the bad value. | 10 * rather than replace the bad value. |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 174 } |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * Return type of [decodeUtf32AsIterable] and variants. The Iterable type | 177 * Return type of [decodeUtf32AsIterable] and variants. The Iterable type |
| 178 * provides an iterator on demand and the iterator will only translate bytes | 178 * provides an iterator on demand and the iterator will only translate bytes |
| 179 * as requested by the user of the iterator. (Note: results are not cached.) | 179 * as requested by the user of the iterator. (Note: results are not cached.) |
| 180 */ | 180 */ |
| 181 class IterableUtf32Decoder implements Iterable<int> { | 181 class IterableUtf32Decoder implements Iterable<int> { |
| 182 final Function codeunitsProvider; | 182 final Function codeunitsProvider; |
| 183 | 183 |
| 184 IterableUtf32Decoder._(Function this.codeunitsProvider); | 184 IterableUtf32Decoder._(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 { | 192 class Utf32BytesDecoder implements _ListRangeIterator { |
| 193 final _ListRangeIterator utf32EncodedBytesIterator; | 193 final _ListRangeIterator utf32EncodedBytesIterator; |
| 194 final int replacementCodepoint; | 194 final int replacementCodepoint; |
| 195 | 195 |
| 196 Utf32BytesDecoder._fromListRangeIterator( | 196 Utf32BytesDecoder._fromListRangeIterator( |
| 197 _ListRangeIterator this.utf32EncodedBytesIterator, | 197 this.utf32EncodedBytesIterator, this.replacementCodepoint); |
| 198 int this.replacementCodepoint); | |
| 199 | 198 |
| 200 factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [ | 199 factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [ |
| 201 int offset = 0, int length, | 200 int offset = 0, int length, |
| 202 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { | 201 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { |
| 203 if (length == null) { | 202 if (length == null) { |
| 204 length = utf32EncodedBytes.length - offset; | 203 length = utf32EncodedBytes.length - offset; |
| 205 } | 204 } |
| 206 if (hasUtf32beBom(utf32EncodedBytes, offset, length)) { | 205 if (hasUtf32beBom(utf32EncodedBytes, offset, length)) { |
| 207 return new Utf32beBytesDecoder(utf32EncodedBytes, offset + 4, length - 4, | 206 return new Utf32beBytesDecoder(utf32EncodedBytes, offset + 4, length - 4, |
| 208 false, replacementCodepoint); | 207 false, replacementCodepoint); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 value += (utf32EncodedBytesIterator.next() << 24); | 308 value += (utf32EncodedBytesIterator.next() << 24); |
| 310 return value; | 309 return value; |
| 311 } | 310 } |
| 312 } | 311 } |
| 313 | 312 |
| 314 bool _validCodepoint(int codepoint) { | 313 bool _validCodepoint(int codepoint) { |
| 315 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || | 314 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || |
| 316 (codepoint > UNICODE_UTF16_RESERVED_HI && | 315 (codepoint > UNICODE_UTF16_RESERVED_HI && |
| 317 codepoint < UNICODE_VALID_RANGE_MAX); | 316 codepoint < UNICODE_VALID_RANGE_MAX); |
| 318 } | 317 } |
| OLD | NEW |