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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 false, replacementCodepoint); | 212 false, replacementCodepoint); |
213 } else { | 213 } else { |
214 return new Utf32beBytesDecoder(utf32EncodedBytes, offset, length, false, | 214 return new Utf32beBytesDecoder(utf32EncodedBytes, offset, length, false, |
215 replacementCodepoint); | 215 replacementCodepoint); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 List<int> decodeRest() { | 219 List<int> decodeRest() { |
220 List<int> codeunits = new List<int>(remaining); | 220 List<int> codeunits = new List<int>(remaining); |
221 int i = 0; | 221 int i = 0; |
222 while (hasNext()) { | 222 while (hasNext) { |
223 codeunits[i++] = next(); | 223 codeunits[i++] = next(); |
224 } | 224 } |
225 return codeunits; | 225 return codeunits; |
226 } | 226 } |
227 | 227 |
228 bool hasNext() => utf32EncodedBytesIterator.hasNext(); | 228 bool get hasNext => utf32EncodedBytesIterator.hasNext; |
229 | 229 |
230 int next() { | 230 int next() { |
231 if (utf32EncodedBytesIterator.remaining < 4) { | 231 if (utf32EncodedBytesIterator.remaining < 4) { |
232 utf32EncodedBytesIterator.skip(utf32EncodedBytesIterator.remaining); | 232 utf32EncodedBytesIterator.skip(utf32EncodedBytesIterator.remaining); |
233 if (replacementCodepoint != null) { | 233 if (replacementCodepoint != null) { |
234 return replacementCodepoint; | 234 return replacementCodepoint; |
235 } else { | 235 } else { |
236 throw new ArgumentError( | 236 throw new ArgumentError( |
237 "Invalid UTF32 at ${utf32EncodedBytesIterator.position}"); | 237 "Invalid UTF32 at ${utf32EncodedBytesIterator.position}"); |
238 } | 238 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 value += (utf32EncodedBytesIterator.next() << 24); | 310 value += (utf32EncodedBytesIterator.next() << 24); |
311 return value; | 311 return value; |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 bool _validCodepoint(int codepoint) { | 315 bool _validCodepoint(int codepoint) { |
316 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || | 316 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || |
317 (codepoint > UNICODE_UTF16_RESERVED_HI && | 317 (codepoint > UNICODE_UTF16_RESERVED_HI && |
318 codepoint < UNICODE_VALID_RANGE_MAX); | 318 codepoint < UNICODE_VALID_RANGE_MAX); |
319 } | 319 } |
OLD | NEW |