| OLD | NEW |
| 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 // Interface for decoders decoding binary data into string data. The | 7 // Interface for decoders decoding binary data into string data. The |
| 8 // decoder keeps track of line breaks during decoding. | 8 // decoder keeps track of line breaks during decoding. |
| 9 abstract class _StringDecoder { | 9 abstract class _StringDecoder { |
| 10 // Add more binary data to be decoded. The ownership of the buffer | 10 // Add more binary data to be decoded. The ownership of the buffer |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 | 296 |
| 297 // Utility class for decoding Windows current code page data delivered | 297 // Utility class for decoding Windows current code page data delivered |
| 298 // as a stream of bytes. | 298 // as a stream of bytes. |
| 299 class _WindowsCodePageDecoder extends _StringDecoderBase { | 299 class _WindowsCodePageDecoder extends _StringDecoderBase { |
| 300 // Process the next chunk of data. | 300 // Process the next chunk of data. |
| 301 bool _processNext() { | 301 bool _processNext() { |
| 302 List<int> bytes = _bufferList.readBytes(_bufferList.length); | 302 List<int> bytes = _bufferList.readBytes(_bufferList.length); |
| 303 for (var charCode in _decodeBytes(bytes).charCodes) { | 303 for (var charCode in _decodeBytes(bytes).codeUnits) { |
| 304 addChar(charCode); | 304 addChar(charCode); |
| 305 } | 305 } |
| 306 return true; | 306 return true; |
| 307 } | 307 } |
| 308 | 308 |
| 309 external static String _decodeBytes(List<int> bytes); | 309 external static String _decodeBytes(List<int> bytes); |
| 310 } | 310 } |
| 311 | 311 |
| 312 | 312 |
| 313 // Interface for encoders encoding string data into binary data. | 313 // Interface for encoders encoding string data into binary data. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 337 return utf8CodeUnits.length; | 337 return utf8CodeUnits.length; |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 | 341 |
| 342 // Utility class for encoding a string into a Latin1 byte stream. | 342 // Utility class for encoding a string into a Latin1 byte stream. |
| 343 class _Latin1Encoder implements _StringEncoder { | 343 class _Latin1Encoder implements _StringEncoder { |
| 344 List<int> encodeString(String string) { | 344 List<int> encodeString(String string) { |
| 345 List<int> result = new Uint8List(string.length); | 345 List<int> result = new Uint8List(string.length); |
| 346 for (int i = 0; i < string.length; i++) { | 346 for (int i = 0; i < string.length; i++) { |
| 347 int charCode = string.charCodeAt(i); | 347 int charCode = string.codeUnitAt(i); |
| 348 if (charCode > 255) { | 348 if (charCode > 255) { |
| 349 throw new EncoderException( | 349 throw new EncoderException( |
| 350 "No ISO_8859_1 encoding for code point $charCode"); | 350 "No ISO_8859_1 encoding for code unit $charCode"); |
| 351 } | 351 } |
| 352 result[i] = charCode; | 352 result[i] = charCode; |
| 353 } | 353 } |
| 354 return result; | 354 return result; |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 | 357 |
| 358 | 358 |
| 359 // Utility class for encoding a string into an ASCII byte stream. | 359 // Utility class for encoding a string into an ASCII byte stream. |
| 360 class _AsciiEncoder implements _StringEncoder { | 360 class _AsciiEncoder implements _StringEncoder { |
| 361 List<int> encodeString(String string) { | 361 List<int> encodeString(String string) { |
| 362 List<int> result = new Uint8List(string.length); | 362 List<int> result = new Uint8List(string.length); |
| 363 for (int i = 0; i < string.length; i++) { | 363 for (int i = 0; i < string.length; i++) { |
| 364 int charCode = string.charCodeAt(i); | 364 int charCode = string.codeUnitAt(i); |
| 365 if (charCode > 127) { | 365 if (charCode > 127) { |
| 366 throw new EncoderException( | 366 throw new EncoderException( |
| 367 "No ASCII encoding for code point $charCode"); | 367 "No ASCII encoding for code unit $charCode"); |
| 368 } | 368 } |
| 369 result[i] = charCode; | 369 result[i] = charCode; |
| 370 } | 370 } |
| 371 return result; | 371 return result; |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 | 374 |
| 375 | 375 |
| 376 // Utility class for encoding a string into a current windows | 376 // Utility class for encoding a string into a current windows |
| 377 // code page byte list. | 377 // code page byte list. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 bool _inputClosed = false; // Is the underlying input stream closed? | 585 bool _inputClosed = false; // Is the underlying input stream closed? |
| 586 bool _closed = false; // Is this stream closed. | 586 bool _closed = false; // Is this stream closed. |
| 587 bool _eof = false; // Has all data been read from the decoder? | 587 bool _eof = false; // Has all data been read from the decoder? |
| 588 Timer _scheduledDataCallback; | 588 Timer _scheduledDataCallback; |
| 589 Timer _scheduledLineCallback; | 589 Timer _scheduledLineCallback; |
| 590 Timer _scheduledCloseCallback; | 590 Timer _scheduledCloseCallback; |
| 591 Function _clientDataHandler; | 591 Function _clientDataHandler; |
| 592 Function _clientLineHandler; | 592 Function _clientLineHandler; |
| 593 Function _clientCloseHandler; | 593 Function _clientCloseHandler; |
| 594 } | 594 } |
| OLD | NEW |