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

Side by Side Diff: sdk/lib/io/string_transformer.dart

Issue 12425004: Fix deprecation warnings in dart:io. Now completely warning free. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « sdk/lib/io/socket.dart ('k') | sdk/lib/io/timer_impl.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.io; 5 part of dart.io;
6 6
7 /** 7 /**
8 * String encodings. 8 * String encodings.
9 */ 9 */
10 class Encoding { 10 class Encoding {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 controller.close(); 150 controller.close();
151 assert(bytes != null); 151 assert(bytes != null);
152 return bytes; 152 return bytes;
153 } 153 }
154 154
155 155
156 class LineTransformer extends StreamEventTransformer<String, String> { 156 class LineTransformer extends StreamEventTransformer<String, String> {
157 const int _LF = 10; 157 const int _LF = 10;
158 const int _CR = 13; 158 const int _CR = 13;
159 159
160 final StringBuffer _buffer = new StringBuffer(); 160 StringBuffer _buffer = new StringBuffer();
161 String _carry; 161 String _carry;
162 162
163 void _handle(String data, StreamSink<String> sink, bool isClosing) { 163 void _handle(String data, StreamSink<String> sink, bool isClosing) {
164 if (_carry != null) { 164 if (_carry != null) {
165 data = _carry.concat(data); 165 data = _carry.concat(data);
166 _carry = null; 166 _carry = null;
167 } 167 }
168 int startPos = 0; 168 int startPos = 0;
169 int pos = 0; 169 int pos = 0;
170 while (pos < data.length) { 170 while (pos < data.length) {
171 int skip = 0; 171 int skip = 0;
172 int char = data.codeUnitAt(pos); 172 int char = data.codeUnitAt(pos);
173 if (char == _LF) { 173 if (char == _LF) {
174 skip = 1; 174 skip = 1;
175 } else if (char == _CR) { 175 } else if (char == _CR) {
176 skip = 1; 176 skip = 1;
177 if (pos + 1 < data.length) { 177 if (pos + 1 < data.length) {
178 if (data.codeUnitAt(pos + 1) == _LF) { 178 if (data.codeUnitAt(pos + 1) == _LF) {
179 skip = 2; 179 skip = 2;
180 } 180 }
181 } else if (!isClosing) { 181 } else if (!isClosing) {
182 _carry = data.substring(startPos); 182 _carry = data.substring(startPos);
183 return; 183 return;
184 } 184 }
185 } 185 }
186 if (skip > 0) { 186 if (skip > 0) {
187 _buffer.add(data.substring(startPos, pos)); 187 _buffer.write(data.substring(startPos, pos));
188 sink.add(_buffer.toString()); 188 sink.add(_buffer.toString());
189 _buffer.clear(); 189 _buffer = new StringBuffer();
190 startPos = pos = pos + skip; 190 startPos = pos = pos + skip;
191 } else { 191 } else {
192 pos++; 192 pos++;
193 } 193 }
194 } 194 }
195 if (pos != startPos) { 195 if (pos != startPos) {
196 // Add remaining 196 // Add remaining
197 _buffer.add(data.substring(startPos, pos)); 197 _buffer.write(data.substring(startPos, pos));
198 } 198 }
199 if (isClosing && !_buffer.isEmpty) { 199 if (isClosing && !_buffer.isEmpty) {
200 sink.add(_buffer.toString()); 200 sink.add(_buffer.toString());
201 _buffer.clear(); 201 _buffer = new StringBuffer();
202 } 202 }
203 } 203 }
204 204
205 void handleData(String data, StreamSink<String> sink) { 205 void handleData(String data, StreamSink<String> sink) {
206 _handle(data, sink, false); 206 _handle(data, sink, false);
207 } 207 }
208 208
209 void handleDone(StreamSink<String> sink) { 209 void handleDone(StreamSink<String> sink) {
210 _handle("", sink, true); 210 _handle("", sink, true);
211 sink.close(); 211 sink.close();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 306
307 // Utility class for decoding Windows current code page data delivered 307 // Utility class for decoding Windows current code page data delivered
308 // as a stream of bytes. 308 // as a stream of bytes.
309 class _WindowsCodePageDecoder extends StreamEventTransformer<List<int>, String> { 309 class _WindowsCodePageDecoder extends StreamEventTransformer<List<int>, String> {
310 void handleData(List<int> data, StreamSink<String> sink) { 310 void handleData(List<int> data, StreamSink<String> sink) {
311 sink.add(_decodeBytes(data)); 311 sink.add(_decodeBytes(data));
312 } 312 }
313 313
314 external static String _decodeBytes(List<int> bytes); 314 external static String _decodeBytes(List<int> bytes);
315 } 315 }
OLDNEW
« no previous file with comments | « sdk/lib/io/socket.dart ('k') | sdk/lib/io/timer_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698