| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 } | 257 } |
| 258 | 258 |
| 259 /** | 259 /** |
| 260 * Provides a fast way to decode the rest of the source bytes in a single | 260 * Provides a fast way to decode the rest of the source bytes in a single |
| 261 * call. This method trades memory for improved speed in that it potentially | 261 * call. This method trades memory for improved speed in that it potentially |
| 262 * over-allocates the List containing results. | 262 * over-allocates the List containing results. |
| 263 */ | 263 */ |
| 264 List<int> decodeRest() { | 264 List<int> decodeRest() { |
| 265 List<int> codeunits = new List<int>(remaining); | 265 List<int> codeunits = new List<int>(remaining); |
| 266 int i = 0; | 266 int i = 0; |
| 267 while (hasNext()) { | 267 while (hasNext) { |
| 268 codeunits[i++] = next(); | 268 codeunits[i++] = next(); |
| 269 } | 269 } |
| 270 if (i == codeunits.length) { | 270 if (i == codeunits.length) { |
| 271 return codeunits; | 271 return codeunits; |
| 272 } else { | 272 } else { |
| 273 List<int> truncCodeunits = new List<int>(i); | 273 List<int> truncCodeunits = new List<int>(i); |
| 274 truncCodeunits.setRange(0, i, codeunits); | 274 truncCodeunits.setRange(0, i, codeunits); |
| 275 return truncCodeunits; | 275 return truncCodeunits; |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 bool hasNext() => utf16EncodedBytesIterator.hasNext(); | 279 bool get hasNext => utf16EncodedBytesIterator.hasNext; |
| 280 | 280 |
| 281 int next() { | 281 int next() { |
| 282 if (utf16EncodedBytesIterator.remaining < 2) { | 282 if (utf16EncodedBytesIterator.remaining < 2) { |
| 283 utf16EncodedBytesIterator.next(); | 283 utf16EncodedBytesIterator.next(); |
| 284 if (replacementCodepoint != null) { | 284 if (replacementCodepoint != null) { |
| 285 return replacementCodepoint; | 285 return replacementCodepoint; |
| 286 } else { | 286 } else { |
| 287 throw new ArgumentError( | 287 throw new ArgumentError( |
| 288 "Invalid UTF16 at ${utf16EncodedBytesIterator.position}"); | 288 "Invalid UTF16 at ${utf16EncodedBytesIterator.position}"); |
| 289 } | 289 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |