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

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

Issue 203603008: Introduce class Sink<T>. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 9 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 | « sdk/lib/async/stream.dart ('k') | sdk/lib/convert/byte_conversion.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 /** 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
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 return result; 87 return result;
88 } 88 }
89 89
90 /** 90 /**
91 * Starts a chunked conversion. 91 * Starts a chunked conversion.
92 * 92 *
93 * The converter works more efficiently if the given [sink] is a 93 * The converter works more efficiently if the given [sink] is a
94 * [ByteConversionSink]. 94 * [ByteConversionSink].
95 */ 95 */
96 StringConversionSink startChunkedConversion( 96 StringConversionSink startChunkedConversion(Sink<List<int>> sink) {
97 ChunkedConversionSink<List<int>> sink) {
98 if (sink is! ByteConversionSink) { 97 if (sink is! ByteConversionSink) {
99 sink = new ByteConversionSink.from(sink); 98 sink = new ByteConversionSink.from(sink);
100 } 99 }
101 return new _UnicodeSubsetEncoderSink(_subsetMask, sink); 100 return new _UnicodeSubsetEncoderSink(_subsetMask, sink);
102 } 101 }
103 102
104 // Override the base-class' bind, to provide a better type. 103 // Override the base-class' bind, to provide a better type.
105 Stream<List<int>> bind(Stream<String> stream) => super.bind(stream); 104 Stream<List<int>> bind(Stream<String> stream) => super.bind(stream);
106 } 105 }
107 106
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 196 }
198 return buffer.toString(); 197 return buffer.toString();
199 } 198 }
200 199
201 /** 200 /**
202 * Starts a chunked conversion. 201 * Starts a chunked conversion.
203 * 202 *
204 * The converter works more efficiently if the given [sink] is a 203 * The converter works more efficiently if the given [sink] is a
205 * [StringConversionSink]. 204 * [StringConversionSink].
206 */ 205 */
207 ByteConversionSink startChunkedConversion( 206 ByteConversionSink startChunkedConversion(Sink<String> sink) {
208 ChunkedConversionSink<String> sink) {
209 StringConversionSink stringSink; 207 StringConversionSink stringSink;
210 if (sink is StringConversionSink) { 208 if (sink is StringConversionSink) {
211 stringSink = sink; 209 stringSink = sink;
212 } else { 210 } else {
213 stringSink = new StringConversionSink.from(sink); 211 stringSink = new StringConversionSink.from(sink);
214 } 212 }
215 // TODO(lrn): Use stringSink.asUtf16Sink() if it becomes available. 213 // TODO(lrn): Use stringSink.asUtf16Sink() if it becomes available.
216 return new _Latin1DecoderSink(_allowInvalid, stringSink); 214 return new _Latin1DecoderSink(_allowInvalid, stringSink);
217 } 215 }
218 216
219 // Override the base-class's bind, to provide a better type. 217 // Override the base-class's bind, to provide a better type.
220 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream); 218 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream);
221 } 219 }
222 220
223 class AsciiDecoder extends _UnicodeSubsetDecoder { 221 class AsciiDecoder extends _UnicodeSubsetDecoder {
224 const AsciiDecoder({bool allowInvalid: false}) 222 const AsciiDecoder({bool allowInvalid: false})
225 : super(allowInvalid, _ASCII_MASK); 223 : super(allowInvalid, _ASCII_MASK);
226 224
227 /** 225 /**
228 * Starts a chunked conversion. 226 * Starts a chunked conversion.
229 * 227 *
230 * The converter works more efficiently if the given [sink] is a 228 * The converter works more efficiently if the given [sink] is a
231 * [StringConversionSink]. 229 * [StringConversionSink].
232 */ 230 */
233 ByteConversionSink startChunkedConversion( 231 ByteConversionSink startChunkedConversion(Sink<String> sink) {
234 ChunkedConversionSink<String> sink) {
235 StringConversionSink stringSink; 232 StringConversionSink stringSink;
236 if (sink is StringConversionSink) { 233 if (sink is StringConversionSink) {
237 stringSink = sink; 234 stringSink = sink;
238 } else { 235 } else {
239 stringSink = new StringConversionSink.from(sink); 236 stringSink = new StringConversionSink.from(sink);
240 } 237 }
241 // TODO(lrn): Use asUtf16Sink when it becomes available. It 238 // TODO(lrn): Use asUtf16Sink when it becomes available. It
242 // works just as well, is likely to have less decoding overhead, 239 // works just as well, is likely to have less decoding overhead,
243 // and make adding U+FFFD easier. 240 // and make adding U+FFFD easier.
244 // At that time, merge this with _Latin1DecoderSink; 241 // At that time, merge this with _Latin1DecoderSink;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 275 }
279 } 276 }
280 } 277 }
281 if (start < end) { 278 if (start < end) {
282 _utf8Sink.addSlice(source, start, end, isLast); 279 _utf8Sink.addSlice(source, start, end, isLast);
283 } else if (isLast) { 280 } else if (isLast) {
284 close(); 281 close();
285 } 282 }
286 } 283 }
287 } 284 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | sdk/lib/convert/byte_conversion.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698