| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 objects of type T. | 5 // Interface for decoders decoding binary data into objects of type T. |
| 6 interface _Decoder<T> { | 6 interface _Decoder<T> { |
| 7 // Add more binary data to be decoded. The ownership of the buffer | 7 // Add more binary data to be decoded. The ownership of the buffer |
| 8 // is transfered to the decoder and the caller most not modify it any more. | 8 // is transfered to the decoder and the caller most not modify it any more. |
| 9 int write(List<int> buffer); | 9 int write(List<int> buffer); |
| 10 | 10 |
| 11 // Returns whether any decoded data is available. | 11 // Returns whether any decoded data is available. |
| 12 bool isEmpty(); | 12 bool isEmpty(); |
| 13 | 13 |
| 14 // Get the data decoded since the last call to decode. | 14 // Get the data decoded since the last call to decode. |
| 15 T get decoded(); | 15 T get decoded(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 | 18 |
| 19 class DecoderException implements Exception { | 19 class DecoderException implements Exception { |
| 20 const DecoderException([String this.message]); | 20 const DecoderException([String msg]) : message = msg; |
| 21 String toString() => "DecoderException: $message"; | 21 String toString() => "DecoderException: $message"; |
| 22 final String message; | 22 final String message; |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 // Utility class for decoding UTF-8 from data delivered as a stream of | 26 // Utility class for decoding UTF-8 from data delivered as a stream of |
| 27 // bytes. | 27 // bytes. |
| 28 class _StringDecoderBase implements _Decoder<String> { | 28 class _StringDecoderBase implements _Decoder<String> { |
| 29 _StringDecoderBase() | 29 _StringDecoderBase() |
| 30 : _bufferList = new _BufferList(), | 30 : _bufferList = new _BufferList(), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Remove the value peeked from the buffer list. | 131 // Remove the value peeked from the buffer list. |
| 132 _bufferList.next(); | 132 _bufferList.next(); |
| 133 } | 133 } |
| 134 _result.addCharCode(value); | 134 _result.addCharCode(value); |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 | 138 |
| 139 | 139 |
| 140 class _StringInputStream implements StringInputStream { | 140 class _StringInputStream implements StringInputStream { |
| 141 _StringInputStream(InputStream this._input, [String this._encoding]) { | 141 _StringInputStream(InputStream this._input, [String encoding]) |
| 142 : _encoding = encoding { |
| 142 if (_encoding === null) { | 143 if (_encoding === null) { |
| 143 _encoding = "UTF-8"; | 144 _encoding = "UTF-8"; |
| 144 } | 145 } |
| 145 if (_encoding == "UTF-8") { | 146 if (_encoding == "UTF-8") { |
| 146 _decoder = new _UTF8Decoder(); | 147 _decoder = new _UTF8Decoder(); |
| 147 } else if (_encoding == "ISO-8859-1") { | 148 } else if (_encoding == "ISO-8859-1") { |
| 148 _decoder = new _Latin1Decoder(); | 149 _decoder = new _Latin1Decoder(); |
| 149 } else if (_encoding == "ASCII") { | 150 } else if (_encoding == "ASCII") { |
| 150 _decoder = new _AsciiDecoder(); | 151 _decoder = new _AsciiDecoder(); |
| 151 } else { | 152 } else { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 String _encoding; | 314 String _encoding; |
| 314 _Decoder _decoder; | 315 _Decoder _decoder; |
| 315 String _buffer; // String can be buffered here if readLine is used. | 316 String _buffer; // String can be buffered here if readLine is used. |
| 316 int _bufferLineStart; // Current offset into _buffer if any. | 317 int _bufferLineStart; // Current offset into _buffer if any. |
| 317 bool _inputClosed = false; // Is the underlying input stream closed? | 318 bool _inputClosed = false; // Is the underlying input stream closed? |
| 318 bool _closed = false; // Is this stream closed. | 319 bool _closed = false; // Is this stream closed. |
| 319 bool _eof = false; // Has all data been read from the decoder? | 320 bool _eof = false; // Has all data been read from the decoder? |
| 320 var _clientDataHandler; | 321 var _clientDataHandler; |
| 321 var _clientCloseHandler; | 322 var _clientCloseHandler; |
| 322 } | 323 } |
| OLD | NEW |