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

Side by Side Diff: lib/utf/utf32.dart

Issue 11049036: Remove spurious types from constructor args that use "this." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months 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
« no previous file with comments | « lib/utf/utf16.dart ('k') | lib/utf/utf8.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 * little-endian byte-order marker (BOM). 166 * little-endian byte-order marker (BOM).
167 */ 167 */
168 bool hasUtf32leBom(List<int> utf32EncodedBytes, [int offset = 0, int length]) { 168 bool hasUtf32leBom(List<int> utf32EncodedBytes, [int offset = 0, int length]) {
169 int end = length != null ? offset + length : utf32EncodedBytes.length; 169 int end = length != null ? offset + length : utf32EncodedBytes.length;
170 return (offset + 4) <= end && 170 return (offset + 4) <= end &&
171 utf32EncodedBytes[offset] == UNICODE_UTF_BOM_LO && 171 utf32EncodedBytes[offset] == UNICODE_UTF_BOM_LO &&
172 utf32EncodedBytes[offset + 1] == UNICODE_UTF_BOM_HI && 172 utf32EncodedBytes[offset + 1] == UNICODE_UTF_BOM_HI &&
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();
177
176 /** 178 /**
177 * Return type of [decodeUtf32AsIterable] and variants. The Iterable type 179 * Return type of [decodeUtf32AsIterable] and variants. The Iterable type
178 * 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
179 * 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.)
180 */ 182 */
181 class IterableUtf32Decoder implements Iterable<int> { 183 class IterableUtf32Decoder implements Iterable<int> {
182 final Function codeunitsProvider; 184 final Utf32BytesDecoderProvider codeunitsProvider;
183 185
184 IterableUtf32Decoder._(Function this.codeunitsProvider); 186 IterableUtf32Decoder._(this.codeunitsProvider);
185 187
186 Utf32BytesDecoder iterator() => codeunitsProvider(); 188 Utf32BytesDecoder iterator() => codeunitsProvider();
187 } 189 }
188 190
189 /** 191 /**
190 * Abstrace parent class converts encoded bytes to codepoints. 192 * Abstrace parent class converts encoded bytes to codepoints.
191 */ 193 */
192 class Utf32BytesDecoder implements _ListRangeIterator { 194 class Utf32BytesDecoder implements _ListRangeIterator {
193 final _ListRangeIterator utf32EncodedBytesIterator; 195 final _ListRangeIterator utf32EncodedBytesIterator;
194 final int replacementCodepoint; 196 final int replacementCodepoint;
195 197
196 Utf32BytesDecoder._fromListRangeIterator( 198 Utf32BytesDecoder._fromListRangeIterator(
197 _ListRangeIterator this.utf32EncodedBytesIterator, 199 this.utf32EncodedBytesIterator, this.replacementCodepoint);
198 int this.replacementCodepoint);
199 200
200 factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [ 201 factory Utf32BytesDecoder(List<int> utf32EncodedBytes, [
201 int offset = 0, int length, 202 int offset = 0, int length,
202 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { 203 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) {
203 if (length == null) { 204 if (length == null) {
204 length = utf32EncodedBytes.length - offset; 205 length = utf32EncodedBytes.length - offset;
205 } 206 }
206 if (hasUtf32beBom(utf32EncodedBytes, offset, length)) { 207 if (hasUtf32beBom(utf32EncodedBytes, offset, length)) {
207 return new Utf32beBytesDecoder(utf32EncodedBytes, offset + 4, length - 4, 208 return new Utf32beBytesDecoder(utf32EncodedBytes, offset + 4, length - 4,
208 false, replacementCodepoint); 209 false, replacementCodepoint);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 value += (utf32EncodedBytesIterator.next() << 24); 310 value += (utf32EncodedBytesIterator.next() << 24);
310 return value; 311 return value;
311 } 312 }
312 } 313 }
313 314
314 bool _validCodepoint(int codepoint) { 315 bool _validCodepoint(int codepoint) {
315 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || 316 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) ||
316 (codepoint > UNICODE_UTF16_RESERVED_HI && 317 (codepoint > UNICODE_UTF16_RESERVED_HI &&
317 codepoint < UNICODE_VALID_RANGE_MAX); 318 codepoint < UNICODE_VALID_RANGE_MAX);
318 } 319 }
OLDNEW
« no previous file with comments | « lib/utf/utf16.dart ('k') | lib/utf/utf8.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698