| 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 /// The current system encoding. | 7 /// The current system encoding. |
| 8 /// | 8 /// |
| 9 /// This us used for converting from bytes to/from String when | 9 /// This us used for converting from bytes to/from String when |
| 10 /// communicating on stdin, stdout and stderr. | 10 /// communicating on stdin, stdout and stderr. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 Converter<List<int>, String> get decoder { | 36 Converter<List<int>, String> get decoder { |
| 37 if (Platform.operatingSystem == "windows") { | 37 if (Platform.operatingSystem == "windows") { |
| 38 return const _WindowsCodePageDecoder(); | 38 return const _WindowsCodePageDecoder(); |
| 39 } else { | 39 } else { |
| 40 return const Utf8Decoder(); | 40 return const Utf8Decoder(); |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 class _WindowsCodePageEncoder extends Converter<String, List<int>> | 45 class _WindowsCodePageEncoder extends Converter<String, List<int>> { |
| 46 implements ChunkedConverter<String, List<int>, String, List<int>> { | |
| 47 const _WindowsCodePageEncoder(); | 46 const _WindowsCodePageEncoder(); |
| 48 | 47 |
| 49 List<int> convert(String input) { | 48 List<int> convert(String input) { |
| 50 List<int> encoded = _encodeString(input); | 49 List<int> encoded = _encodeString(input); |
| 51 if (encoded == null) { | 50 if (encoded == null) { |
| 52 throw new FormatException("Invalid character for encoding"); | 51 throw new FormatException("Invalid character for encoding"); |
| 53 } | 52 } |
| 54 return encoded; | 53 return encoded; |
| 55 } | 54 } |
| 56 | 55 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 | 85 |
| 87 void addSlice(String source, int start, int end, bool isLast) { | 86 void addSlice(String source, int start, int end, bool isLast) { |
| 88 if (start != 0 || end != source.length) { | 87 if (start != 0 || end != source.length) { |
| 89 source = source.substring(start, end); | 88 source = source.substring(start, end); |
| 90 } | 89 } |
| 91 add(source); | 90 add(source); |
| 92 if (isLast) close(); | 91 if (isLast) close(); |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 | 94 |
| 96 class _WindowsCodePageDecoder extends Converter<List<int>, String> | 95 class _WindowsCodePageDecoder extends Converter<List<int>, String> { |
| 97 implements ChunkedConverter<List<int>, String, List<int>, String> { | |
| 98 const _WindowsCodePageDecoder(); | 96 const _WindowsCodePageDecoder(); |
| 99 | 97 |
| 100 String convert(List<int> input) { | 98 String convert(List<int> input) { |
| 101 return _decodeBytes(input); | 99 return _decodeBytes(input); |
| 102 } | 100 } |
| 103 | 101 |
| 104 /** | 102 /** |
| 105 * Starts a chunked conversion. | 103 * Starts a chunked conversion. |
| 106 */ | 104 */ |
| 107 ByteConversionSink startChunkedConversion(Sink<String> sink) { | 105 ByteConversionSink startChunkedConversion(Sink<String> sink) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 120 _WindowsCodePageDecoderSink(this._sink); | 118 _WindowsCodePageDecoderSink(this._sink); |
| 121 | 119 |
| 122 void close() { | 120 void close() { |
| 123 _sink.close(); | 121 _sink.close(); |
| 124 } | 122 } |
| 125 | 123 |
| 126 void add(List<int> bytes) { | 124 void add(List<int> bytes) { |
| 127 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); | 125 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); |
| 128 } | 126 } |
| 129 } | 127 } |
| OLD | NEW |