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

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

Issue 12610006: Renamed StreamSink to EventSink. Renamed signalError to addError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed inheritance back! Now create StreamSink instead of EventSink where we create them. Created 7 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
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.utf; 5 part of dart.utf;
6 6
7 class _HelperStreamController<T> extends StreamController<T> { 7 class _HelperStreamController<T> extends StreamController<T> {
8 final Function onPauseChanged; 8 final Function onPauseChanged;
9 9
10 _HelperStreamController(this.onPauseChanged); 10 _HelperStreamController(this.onPauseChanged);
11 11
12 void onPauseStateChange() { 12 void onPauseStateChange() {
13 onPauseChanged(); 13 onPauseChanged();
14 } 14 }
15 } 15 }
16 16
17 abstract class _StringDecoder 17 abstract class _StringDecoder
18 extends StreamEventTransformer<List<int>, String> { 18 extends StreamEventTransformer<List<int>, String> {
19 List<int> _carry; 19 List<int> _carry;
20 List<int> _buffer; 20 List<int> _buffer;
21 int _replacementChar; 21 int _replacementChar;
22 22
23 _StringDecoder(int this._replacementChar); 23 _StringDecoder(int this._replacementChar);
24 24
25 void handleData(List<int> bytes, StreamSink<String> sink) { 25 void handleData(List<int> bytes, EventSink<String> sink) {
26 _buffer = <int>[]; 26 _buffer = <int>[];
27 List<int> carry = _carry; 27 List<int> carry = _carry;
28 _carry = null; 28 _carry = null;
29 int pos = 0; 29 int pos = 0;
30 int available = bytes.length; 30 int available = bytes.length;
31 // If we have carry-over data, start from negative index, indicating carry 31 // If we have carry-over data, start from negative index, indicating carry
32 // index. 32 // index.
33 int goodChars = 0; 33 int goodChars = 0;
34 if (carry != null) pos = -carry.length; 34 if (carry != null) pos = -carry.length;
35 while (pos < available) { 35 while (pos < available) {
(...skipping 26 matching lines...) Expand all
62 goodChars = _buffer.length; 62 goodChars = _buffer.length;
63 } 63 }
64 } 64 }
65 if (_buffer.length > 0) { 65 if (_buffer.length > 0) {
66 // Limit to 'goodChars', if lower than actual charCodes in the buffer. 66 // Limit to 'goodChars', if lower than actual charCodes in the buffer.
67 sink.add(new String.fromCharCodes(_buffer)); 67 sink.add(new String.fromCharCodes(_buffer));
68 } 68 }
69 _buffer = null; 69 _buffer = null;
70 } 70 }
71 71
72 void handleDone(StreamSink<String> sink) { 72 void handleDone(EventSink<String> sink) {
73 if (_carry != null) { 73 if (_carry != null) {
74 sink.add(new String.fromCharCodes( 74 sink.add(new String.fromCharCodes(
75 new List.filled(_carry.length, _replacementChar))); 75 new List.filled(_carry.length, _replacementChar)));
76 } 76 }
77 sink.close(); 77 sink.close();
78 } 78 }
79 79
80 int _processBytes(int getNext()); 80 int _processBytes(int getNext());
81 81
82 void _addChar(int char) { 82 void _addChar(int char) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 _addChar(value); 136 _addChar(value);
137 return 1; 137 return 1;
138 } 138 }
139 } 139 }
140 140
141 141
142 abstract class _StringEncoder 142 abstract class _StringEncoder
143 extends StreamEventTransformer<String, List<int>> { 143 extends StreamEventTransformer<String, List<int>> {
144 144
145 void handleData(String data, StreamSink<List<int>> sink) { 145 void handleData(String data, EventSink<List<int>> sink) {
146 sink.add(_processString(data)); 146 sink.add(_processString(data));
147 } 147 }
148 148
149 List<int> _processString(String string); 149 List<int> _processString(String string);
150 } 150 }
151 151
152 /** 152 /**
153 * StringTransformer that UTF-8 encodes a stream of strings. 153 * StringTransformer that UTF-8 encodes a stream of strings.
154 */ 154 */
155 class Utf8EncoderTransformer extends _StringEncoder { 155 class Utf8EncoderTransformer extends _StringEncoder {
(...skipping 23 matching lines...) Expand all
179 } 179 }
180 for (int i = additionalBytes; i > 0; i--) { 180 for (int i = additionalBytes; i > 0; i--) {
181 // 10xxxxxx (xxxxxx is next 6 bits from the top). 181 // 10xxxxxx (xxxxxx is next 6 bits from the top).
182 bytes.add(((charCode >> (6 * (i - 1))) & 0x3F) | 0x80); 182 bytes.add(((charCode >> (6 * (i - 1))) & 0x3F) | 0x80);
183 } 183 }
184 pos += additionalBytes + 1; 184 pos += additionalBytes + 1;
185 } 185 }
186 return bytes; 186 return bytes;
187 } 187 }
188 } 188 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698