| 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 const int _UTF8_ONE_BYTE_MAX = 0x7f; | 5 const int _UTF8_ONE_BYTE_MAX = 0x7f; |
| 6 const int _UTF8_TWO_BYTE_MAX = 0x7ff; | 6 const int _UTF8_TWO_BYTE_MAX = 0x7ff; |
| 7 const int _UTF8_THREE_BYTE_MAX = 0xffff; | 7 const int _UTF8_THREE_BYTE_MAX = 0xffff; |
| 8 | 8 |
| 9 const int _UTF8_LO_SIX_BIT_MASK = 0x3f; | 9 const int _UTF8_LO_SIX_BIT_MASK = 0x3f; |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { | 120 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { |
| 121 return new Utf8Decoder(utf8EncodedBytes, offset, length, | 121 return new Utf8Decoder(utf8EncodedBytes, offset, length, |
| 122 replacementCodepoint).decodeRest(); | 122 replacementCodepoint).decodeRest(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * Return type of [decodeUtf8AsIterable] and variants. The Iterable type | 126 * Return type of [decodeUtf8AsIterable] and variants. The Iterable type |
| 127 * provides an iterator on demand and the iterator will only translate bytes | 127 * provides an iterator on demand and the iterator will only translate bytes |
| 128 * as requested by the user of the iterator. (Note: results are not cached.) | 128 * as requested by the user of the iterator. (Note: results are not cached.) |
| 129 */ | 129 */ |
| 130 // TODO(floitsch): Consider removing the extend and switch to implements since |
| 131 // that's cheaper to allocate. |
| 130 class IterableUtf8Decoder extends Iterable<int> { | 132 class IterableUtf8Decoder extends Iterable<int> { |
| 131 final List<int> bytes; | 133 final List<int> bytes; |
| 132 final int offset; | 134 final int offset; |
| 133 final int length; | 135 final int length; |
| 134 final int replacementCodepoint; | 136 final int replacementCodepoint; |
| 135 | 137 |
| 136 IterableUtf8Decoder(this.bytes, [this.offset = 0, this.length = null, | 138 IterableUtf8Decoder(this.bytes, [this.offset = 0, this.length = null, |
| 137 this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); | 139 this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); |
| 138 | 140 |
| 139 Utf8Decoder get iterator => | 141 Utf8Decoder get iterator => |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 return true; | 264 return true; |
| 263 } else if (replacementCodepoint != null) { | 265 } else if (replacementCodepoint != null) { |
| 264 _current = replacementCodepoint; | 266 _current = replacementCodepoint; |
| 265 return true; | 267 return true; |
| 266 } else { | 268 } else { |
| 267 throw new ArgumentError( | 269 throw new ArgumentError( |
| 268 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); | 270 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); |
| 269 } | 271 } |
| 270 } | 272 } |
| 271 } | 273 } |
| OLD | NEW |