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

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

Issue 1964953003: Make dart:convert strong mode clean. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove unnecessary dynamics. Created 4 years, 7 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
« no previous file with comments | « sdk/lib/convert/string_conversion.dart ('k') | sdk/lib/io/data_transformer.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.convert; 5 part of dart.convert;
6 6
7 /** The Unicode Replacement character `U+FFFD` (�). */ 7 /** The Unicode Replacement character `U+FFFD` (�). */
8 const int UNICODE_REPLACEMENT_CHARACTER_RUNE = 0xFFFD; 8 const int UNICODE_REPLACEMENT_CHARACTER_RUNE = 0xFFFD;
9 9
10 /** The Unicode Byte Order Marker (BOM) character `U+FEFF`. */ 10 /** The Unicode Byte Order Marker (BOM) character `U+FEFF`. */
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 Utf8Encoder get encoder => const Utf8Encoder(); 69 Utf8Encoder get encoder => const Utf8Encoder();
70 Utf8Decoder get decoder { 70 Utf8Decoder get decoder {
71 return new Utf8Decoder(allowMalformed: _allowMalformed); 71 return new Utf8Decoder(allowMalformed: _allowMalformed);
72 } 72 }
73 } 73 }
74 74
75 /** 75 /**
76 * This class converts strings to their UTF-8 code units (a list of 76 * This class converts strings to their UTF-8 code units (a list of
77 * unsigned 8-bit integers). 77 * unsigned 8-bit integers).
78 */ 78 */
79 class Utf8Encoder extends 79 class Utf8Encoder extends Converter<String, List<int>> {
80 ChunkedConverter<String, List<int>, String, List<int>> {
81 80
82 const Utf8Encoder(); 81 const Utf8Encoder();
83 82
84 /** 83 /**
85 * Converts [string] to its UTF-8 code units (a list of 84 * Converts [string] to its UTF-8 code units (a list of
86 * unsigned 8-bit integers). 85 * unsigned 8-bit integers).
87 * 86 *
88 * If [start] and [end] are provided, only the substring 87 * If [start] and [end] are provided, only the substring
89 * `string.substring(start, end)` is converted. 88 * `string.substring(start, end)` is converted.
90 */ 89 */
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 297 }
299 298
300 // TODO(floitsch): implement asUtf8Sink. Sligthly complicated because it 299 // TODO(floitsch): implement asUtf8Sink. Sligthly complicated because it
301 // needs to deal with malformed input. 300 // needs to deal with malformed input.
302 } 301 }
303 302
304 /** 303 /**
305 * This class converts UTF-8 code units (lists of unsigned 8-bit integers) 304 * This class converts UTF-8 code units (lists of unsigned 8-bit integers)
306 * to a string. 305 * to a string.
307 */ 306 */
308 class Utf8Decoder extends 307 class Utf8Decoder extends Converter<List<int>, String> {
309 ChunkedConverter<List<int>, String, List<int>, String> {
310 final bool _allowMalformed; 308 final bool _allowMalformed;
311 309
312 /** 310 /**
313 * Instantiates a new [Utf8Decoder]. 311 * Instantiates a new [Utf8Decoder].
314 * 312 *
315 * The optional [allowMalformed] argument defines how [convert] deals 313 * The optional [allowMalformed] argument defines how [convert] deals
316 * with invalid or unterminated character sequences. 314 * with invalid or unterminated character sequences.
317 * 315 *
318 * If it is `true` [convert] replaces invalid (or unterminated) character 316 * If it is `true` [convert] replaces invalid (or unterminated) character
319 * sequences with the Unicode Replacement character `U+FFFD` (�). Otherwise 317 * sequences with the Unicode Replacement character `U+FFFD` (�). Otherwise
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 stringSink = sink; 360 stringSink = sink;
363 } else { 361 } else {
364 stringSink = new StringConversionSink.from(sink); 362 stringSink = new StringConversionSink.from(sink);
365 } 363 }
366 return stringSink.asUtf8Sink(_allowMalformed); 364 return stringSink.asUtf8Sink(_allowMalformed);
367 } 365 }
368 366
369 // Override the base-classes bind, to provide a better type. 367 // Override the base-classes bind, to provide a better type.
370 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream); 368 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream);
371 369
372 external Converter<List<int>,dynamic> fuse(Converter<String, dynamic> next); 370 external Converter<List<int>, dynamic/*=T*/> fuse/*<T>*/(
371 Converter<String, dynamic/*=T*/> next);
373 372
374 external static String _convertIntercepted( 373 external static String _convertIntercepted(
375 bool allowMalformed, List<int> codeUnits, int start, int end); 374 bool allowMalformed, List<int> codeUnits, int start, int end);
376 } 375 }
377 376
378 // UTF-8 constants. 377 // UTF-8 constants.
379 const int _ONE_BYTE_LIMIT = 0x7f; // 7 bits 378 const int _ONE_BYTE_LIMIT = 0x7f; // 7 bits
380 const int _TWO_BYTE_LIMIT = 0x7ff; // 11 bits 379 const int _TWO_BYTE_LIMIT = 0x7ff; // 11 bits
381 const int _THREE_BYTE_LIMIT = 0xffff; // 16 bits 380 const int _THREE_BYTE_LIMIT = 0xffff; // 16 bits
382 const int _FOUR_BYTE_LIMIT = 0x10ffff; // 21 bits, truncated to Unicode max. 381 const int _FOUR_BYTE_LIMIT = 0x10ffff; // 21 bits, truncated to Unicode max.
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 563 }
565 break loop; 564 break loop;
566 } 565 }
567 if (expectedUnits > 0) { 566 if (expectedUnits > 0) {
568 _value = value; 567 _value = value;
569 _expectedUnits = expectedUnits; 568 _expectedUnits = expectedUnits;
570 _extraUnits = extraUnits; 569 _extraUnits = extraUnits;
571 } 570 }
572 } 571 }
573 } 572 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/string_conversion.dart ('k') | sdk/lib/io/data_transformer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698