Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Side by Side Diff: sdk/lib/utf/utf8.dart

Issue 11363252: Extend Iterable instead of implementing it. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Address Stephen's comments. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 class IterableUtf8Decoder implements Iterable<int> { 130 class IterableUtf8Decoder extends Iterable<int> {
131 final List<int> bytes; 131 final List<int> bytes;
132 final int offset; 132 final int offset;
133 final int length; 133 final int length;
134 final int replacementCodepoint; 134 final int replacementCodepoint;
135 135
136 IterableUtf8Decoder(this.bytes, [this.offset = 0, this.length = null, 136 IterableUtf8Decoder(this.bytes, [this.offset = 0, this.length = null,
137 this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]); 137 this.replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]);
138 138
139 Utf8Decoder iterator() => new Utf8Decoder(bytes, offset, length, 139 Utf8Decoder iterator() => new Utf8Decoder(bytes, offset, length,
140 replacementCodepoint); 140 replacementCodepoint);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (validSequence && nonOverlong && inRange) { 251 if (validSequence && nonOverlong && inRange) {
252 return value; 252 return value;
253 } else if (replacementCodepoint != null) { 253 } else if (replacementCodepoint != null) {
254 return replacementCodepoint; 254 return replacementCodepoint;
255 } else { 255 } else {
256 throw new ArgumentError( 256 throw new ArgumentError(
257 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}"); 257 "Invalid UTF8 at ${utf8EncodedBytesIterator.position - j}");
258 } 258 }
259 } 259 }
260 } 260 }
OLDNEW
« sdk/lib/utf/utf16.dart ('K') | « sdk/lib/utf/utf32.dart ('k') | sdk/lib/utf/utf_core.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698