| 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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 utf32EncodedBytes[offset + 2] == 0 && utf32EncodedBytes[offset + 3] == 0; | 173 utf32EncodedBytes[offset + 2] == 0 && utf32EncodedBytes[offset + 3] == 0; |
| 174 } | 174 } |
| 175 | 175 |
| 176 typedef Utf32BytesDecoder Utf32BytesDecoderProvider(); | 176 typedef Utf32BytesDecoder Utf32BytesDecoderProvider(); |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * Return type of [decodeUtf32AsIterable] and variants. The Iterable type | 179 * Return type of [decodeUtf32AsIterable] and variants. The Iterable type |
| 180 * provides an iterator on demand and the iterator will only translate bytes | 180 * provides an iterator on demand and the iterator will only translate bytes |
| 181 * as requested by the user of the iterator. (Note: results are not cached.) | 181 * as requested by the user of the iterator. (Note: results are not cached.) |
| 182 */ | 182 */ |
| 183 // TODO(floitsch): Consider removing the extend and switch to implements since |
| 184 // that's cheaper to allocate. |
| 183 class IterableUtf32Decoder extends Iterable<int> { | 185 class IterableUtf32Decoder extends Iterable<int> { |
| 184 final Utf32BytesDecoderProvider codeunitsProvider; | 186 final Utf32BytesDecoderProvider codeunitsProvider; |
| 185 | 187 |
| 186 IterableUtf32Decoder._(this.codeunitsProvider); | 188 IterableUtf32Decoder._(this.codeunitsProvider); |
| 187 | 189 |
| 188 Utf32BytesDecoder get iterator => codeunitsProvider(); | 190 Utf32BytesDecoder get iterator => codeunitsProvider(); |
| 189 } | 191 } |
| 190 | 192 |
| 191 /** | 193 /** |
| 192 * Abstrace parent class converts encoded bytes to codepoints. | 194 * Abstrace parent class converts encoded bytes to codepoints. |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 value += (utf32EncodedBytesIterator.current << 24); | 327 value += (utf32EncodedBytesIterator.current << 24); |
| 326 return value; | 328 return value; |
| 327 } | 329 } |
| 328 } | 330 } |
| 329 | 331 |
| 330 bool _validCodepoint(int codepoint) { | 332 bool _validCodepoint(int codepoint) { |
| 331 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || | 333 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || |
| 332 (codepoint > UNICODE_UTF16_RESERVED_HI && | 334 (codepoint > UNICODE_UTF16_RESERVED_HI && |
| 333 codepoint < UNICODE_VALID_RANGE_MAX); | 335 codepoint < UNICODE_VALID_RANGE_MAX); |
| 334 } | 336 } |
| OLD | NEW |