@@ -35,7 +35,7 @@ class AsciiCodec extends Encoding {
35
35
/// Encoders will not accept invalid (non ASCII) characters.
36
36
const AsciiCodec ({bool allowInvalid = false }) : _allowInvalid = allowInvalid;
37
37
38
- /// The name of this codec, "us-ascii".
38
+ /// The name of this codec is "us-ascii".
39
39
String get name => "us-ascii" ;
40
40
41
41
Uint8List encode (String source) => encoder.convert (source);
@@ -103,7 +103,15 @@ class _UnicodeSubsetEncoder extends Converter<String, List<int>> {
103
103
Stream <List <int >> bind (Stream <String > stream) => super .bind (stream);
104
104
}
105
105
106
- /// This class converts strings of only ASCII characters to bytes.
106
+ /// Converts strings of only ASCII characters to bytes.
107
+ ///
108
+ /// Example:
109
+ /// ```dart import:typed_data
110
+ /// const asciiEncoder = AsciiEncoder();
111
+ /// const sample = 'Dart';
112
+ /// final asciiValues = asciiEncoder.convert(sample);
113
+ /// print(asciiValues); // [68, 97, 114, 116]
114
+ /// ```
107
115
class AsciiEncoder extends _UnicodeSubsetEncoder {
108
116
const AsciiEncoder () : super (_asciiMask);
109
117
}
@@ -195,6 +203,29 @@ abstract class _UnicodeSubsetDecoder extends Converter<List<int>, String> {
195
203
Stream <String > bind (Stream <List <int >> stream) => super .bind (stream);
196
204
}
197
205
206
+ /// Converts ASCII bytes to string.
207
+ ///
208
+ /// Example:
209
+ /// ```dart
210
+ /// const asciiDecoder = AsciiDecoder();
211
+ /// final asciiValues = [68, 97, 114, 116];
212
+ /// final result = asciiDecoder.convert(asciiValues);
213
+ /// print(result); // Dart
214
+ /// ```
215
+ /// Throws a [FormatException] if [bytes] contains values that are not
216
+ /// in the range 0 .. 127, and [allowInvalid] is `false` (the default).
217
+ ///
218
+ /// If [allowInvalid] is `true` , any byte outside the range 0..127 is replaced
219
+ /// by the Unicode replacement character, U+FFFD ('�').
220
+ ///
221
+ /// Example with `allowInvalid` set to true:
222
+ /// ```dart
223
+ /// const asciiDecoder = AsciiDecoder(allowInvalid: true);
224
+ /// final asciiValues = [68, 97, 114, 116, 20, 0xFF];
225
+ /// final result = asciiDecoder.convert(asciiValues);
226
+ /// print(result); // Dart �
227
+ /// print(result.codeUnits.last.toRadixString(16)); // fffd
228
+ /// ```
198
229
class AsciiDecoder extends _UnicodeSubsetDecoder {
199
230
const AsciiDecoder ({bool allowInvalid = false })
200
231
: super (allowInvalid, _asciiMask);
0 commit comments