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

Side by Side Diff: runtime/bin/string_stream.dart

Issue 10379018: Revert "Revert "Implement {Int,Uint}{8,16,32,64} and Float{32,64} typed arrays."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // Interface for decoders decoding binary data into string data. The 5 // Interface for decoders decoding binary data into string data. The
6 // decoder keeps track of line breaks during decoding. 6 // decoder keeps track of line breaks during decoding.
7 interface _StringDecoder { 7 interface _StringDecoder {
8 // Add more binary data to be decoded. The ownership of the buffer 8 // Add more binary data to be decoded. The ownership of the buffer
9 // is transfered to the decoder and the caller most not modify it any more. 9 // is transfered to the decoder and the caller most not modify it any more.
10 int write(List<int> buffer); 10 int write(List<int> buffer);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // Interface for encoders encoding string data into binary data. 232 // Interface for encoders encoding string data into binary data.
233 interface _StringEncoder { 233 interface _StringEncoder {
234 List<int> encodeString(String string); 234 List<int> encodeString(String string);
235 } 235 }
236 236
237 237
238 // Utility class for encoding a string into UTF-8 byte stream. 238 // Utility class for encoding a string into UTF-8 byte stream.
239 class _UTF8Encoder implements _StringEncoder { 239 class _UTF8Encoder implements _StringEncoder {
240 List<int> encodeString(String string) { 240 List<int> encodeString(String string) {
241 int size = _encodingSize(string); 241 int size = _encodingSize(string);
242 ByteArray result = new ByteArray(size); 242 List<int> result = new Uint8List(size);
243 _encodeString(string, result); 243 _encodeString(string, result);
244 return result; 244 return result;
245 } 245 }
246 246
247 static int _encodingSize(String string) => _encodeString(string, null); 247 static int _encodingSize(String string) => _encodeString(string, null);
248 248
249 static int _encodeString(String string, List<int> buffer) { 249 static int _encodeString(String string, List<int> buffer) {
250 int pos = 0; 250 int pos = 0;
251 int length = string.length; 251 int length = string.length;
252 for (int i = 0; i < length; i++) { 252 for (int i = 0; i < length; i++) {
(...skipping 26 matching lines...) Expand all
279 } 279 }
280 } 280 }
281 return pos; 281 return pos;
282 } 282 }
283 } 283 }
284 284
285 285
286 // Utility class for encoding a string into a Latin1 byte stream. 286 // Utility class for encoding a string into a Latin1 byte stream.
287 class _Latin1Encoder implements _StringEncoder { 287 class _Latin1Encoder implements _StringEncoder {
288 List<int> encodeString(String string) { 288 List<int> encodeString(String string) {
289 ByteArray result = new ByteArray(string.length); 289 List<int> result = new Uint8List(string.length);
290 for (int i = 0; i < string.length; i++) { 290 for (int i = 0; i < string.length; i++) {
291 int charCode = string.charCodeAt(i); 291 int charCode = string.charCodeAt(i);
292 if (charCode > 255) { 292 if (charCode > 255) {
293 throw new EncoderException( 293 throw new EncoderException(
294 "No ISO_8859_1 encoding for code point $charCode"); 294 "No ISO_8859_1 encoding for code point $charCode");
295 } 295 }
296 result[i] = charCode; 296 result[i] = charCode;
297 } 297 }
298 return result; 298 return result;
299 } 299 }
300 } 300 }
301 301
302 302
303 // Utility class for encoding a string into an ASCII byte stream. 303 // Utility class for encoding a string into an ASCII byte stream.
304 class _AsciiEncoder implements _StringEncoder { 304 class _AsciiEncoder implements _StringEncoder {
305 List<int> encodeString(String string) { 305 List<int> encodeString(String string) {
306 ByteArray result = new ByteArray(string.length); 306 List<int> result = new Uint8List(string.length);
307 for (int i = 0; i < string.length; i++) { 307 for (int i = 0; i < string.length; i++) {
308 int charCode = string.charCodeAt(i); 308 int charCode = string.charCodeAt(i);
309 if (charCode > 127) { 309 if (charCode > 127) {
310 throw new EncoderException( 310 throw new EncoderException(
311 "No ASCII encoding for code point $charCode"); 311 "No ASCII encoding for code point $charCode");
312 } 312 }
313 result[i] = charCode; 313 result[i] = charCode;
314 } 314 }
315 return result; 315 return result;
316 } 316 }
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 bool _inputClosed = false; // Is the underlying input stream closed? 510 bool _inputClosed = false; // Is the underlying input stream closed?
511 bool _closed = false; // Is this stream closed. 511 bool _closed = false; // Is this stream closed.
512 bool _eof = false; // Has all data been read from the decoder? 512 bool _eof = false; // Has all data been read from the decoder?
513 Timer _scheduledDataCallback; 513 Timer _scheduledDataCallback;
514 Timer _scheduledLineCallback; 514 Timer _scheduledLineCallback;
515 Timer _scheduledCloseCallback; 515 Timer _scheduledCloseCallback;
516 Function _clientDataHandler; 516 Function _clientDataHandler;
517 Function _clientLineHandler; 517 Function _clientLineHandler;
518 Function _clientCloseHandler; 518 Function _clientCloseHandler;
519 } 519 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698