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

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

Issue 22872012: Remove Encoding-enum from dart:io and add interface in dart:convert. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix ddbg. Created 7 years, 4 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
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 /** 7 /**
8 * An instance of the default implementation of the [AsciiCodec]. 8 * An instance of the default implementation of the [AsciiCodec].
9 * 9 *
10 * This instance provides a convenient access to the most common ASCII 10 * This instance provides a convenient access to the most common ASCII
11 * use cases. 11 * use cases.
12 * 12 *
13 * Examples: 13 * Examples:
14 * 14 *
15 * var encoded = ASCII.encode("This is ASCII!"); 15 * var encoded = ASCII.encode("This is ASCII!");
16 * var decoded = ASCII.decode([0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 16 * var decoded = ASCII.decode([0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73,
17 * 0x20, 0x41, 0x53, 0x43, 0x49, 0x49, 0x21]); 17 * 0x20, 0x41, 0x53, 0x43, 0x49, 0x49, 0x21]);
18 */ 18 */
19 const ASCII = const AsciiCodec(); 19 const ASCII = const AsciiCodec();
20 20
21 const int _ASCII_MASK = 0x7F; 21 const int _ASCII_MASK = 0x7F;
22 22
23 /** 23 /**
24 * An [AsciiCodec] allows encoding strings as ASCII bytes 24 * An [AsciiCodec] allows encoding strings as ASCII bytes
25 * and decoding ASCII bytes to strings. 25 * and decoding ASCII bytes to strings.
26 */ 26 */
27 class AsciiCodec extends _Encoding { 27 class AsciiCodec extends Encoding {
28 final bool _allowInvalid; 28 final bool _allowInvalid;
29 /** 29 /**
30 * Instantiates a new [AsciiCodec]. 30 * Instantiates a new [AsciiCodec].
31 * 31 *
32 * If [allowInvalid] is true, the [decode] method and the converter 32 * If [allowInvalid] is true, the [decode] method and the converter
33 * returned by [decoder] will default to allowing invalid values. 33 * returned by [decoder] will default to allowing invalid values.
34 * If allowing invalid values, the values will be decoded into the Unicode 34 * If allowing invalid values, the values will be decoded into the Unicode
35 * Replacement character (U+FFFD). If not, an exception will be thrown. 35 * Replacement character (U+FFFD). If not, an exception will be thrown.
36 * Calls to the [decode] method can choose to override this default. 36 * Calls to the [decode] method can choose to override this default.
37 * 37 *
38 * Encoders will not accept invalid (non Latin-1) characters. 38 * Encoders will not accept invalid (non Latin-1) characters.
39 */ 39 */
40 const AsciiCodec({bool allowInvalid: false}) : _allowInvalid = allowInvalid; 40 const AsciiCodec({bool allowInvalid: false}) : _allowInvalid = allowInvalid;
41 41
42 String get name => "us-ascii";
43
42 /** 44 /**
43 * Decodes the ASCII [bytes] (a list of unsigned 7-bit integers) to the 45 * Decodes the ASCII [bytes] (a list of unsigned 7-bit integers) to the
44 * corresponding string. 46 * corresponding string.
45 * 47 *
46 * If [bytes] contains values that are not in the range 0 .. 127, the decoder 48 * If [bytes] contains values that are not in the range 0 .. 127, the decoder
47 * will eventually throw a [FormatException]. 49 * will eventually throw a [FormatException].
48 * 50 *
49 * If [allowInvalid] is not provided, it defaults to the value used to create 51 * If [allowInvalid] is not provided, it defaults to the value used to create
50 * this [AsciiCodec]. 52 * this [AsciiCodec].
51 */ 53 */
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 278 }
277 } 279 }
278 } 280 }
279 if (start < end) { 281 if (start < end) {
280 _utf8Sink.addSlice(source, start, end, isLast); 282 _utf8Sink.addSlice(source, start, end, isLast);
281 } else if (isLast) { 283 } else if (isLast) {
282 close(); 284 close();
283 } 285 }
284 } 286 }
285 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698