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 const SYSTEM_ENCODING = const SystemEncoding(); | 7 const SYSTEM_ENCODING = const SystemEncoding(); |
8 | 8 |
9 /** | 9 /** |
10 * The system encoding is the current code page on Windows and UTF-8 on | 10 * The system encoding is the current code page on Windows and UTF-8 on |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // Override the base-class' bind, to provide a better type. | 56 // Override the base-class' bind, to provide a better type. |
57 Stream<List<int>> bind(Stream<String> stream) => super.bind(stream); | 57 Stream<List<int>> bind(Stream<String> stream) => super.bind(stream); |
58 | 58 |
59 external static List<int> _encodeString(String string); | 59 external static List<int> _encodeString(String string); |
60 } | 60 } |
61 | 61 |
62 class _WindowsCodePageEncoderSink extends StringConversionSinkBase { | 62 class _WindowsCodePageEncoderSink extends StringConversionSinkBase { |
63 // TODO(floitsch): provide more efficient conversions when the input is | 63 // TODO(floitsch): provide more efficient conversions when the input is |
64 // not a String. | 64 // not a String. |
65 | 65 |
66 final ByteConversionSink _sink; | 66 final ChunkedConversionSink<List<int>> _sink; |
67 | 67 |
68 _WindowsCodePageEncoderSink(this._sink); | 68 _WindowsCodePageEncoderSink(this._sink); |
69 | 69 |
70 void close() { | 70 void close() { |
71 _sink.close(); | 71 _sink.close(); |
72 } | 72 } |
73 | 73 |
74 void add(String string) { | 74 void add(String string) { |
75 List<int> encoded = _WindowsCodePageEncoder._encodeString(string); | 75 List<int> encoded = _WindowsCodePageEncoder._encodeString(string); |
76 if (encoded == null) { | 76 if (encoded == null) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // Override the base-class' bind, to provide a better type. | 108 // Override the base-class' bind, to provide a better type. |
109 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream); | 109 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream); |
110 | 110 |
111 external static String _decodeBytes(List<int> bytes); | 111 external static String _decodeBytes(List<int> bytes); |
112 } | 112 } |
113 | 113 |
114 class _WindowsCodePageDecoderSink extends ByteConversionSinkBase { | 114 class _WindowsCodePageDecoderSink extends ByteConversionSinkBase { |
115 // TODO(floitsch): provide more efficient conversions when the input is | 115 // TODO(floitsch): provide more efficient conversions when the input is |
116 // a slice. | 116 // a slice. |
117 | 117 |
118 final StringConversionSink _sink; | 118 final ChunkedConversionSink<String> _sink; |
119 | 119 |
120 _WindowsCodePageDecoderSink(this._sink); | 120 _WindowsCodePageDecoderSink(this._sink); |
121 | 121 |
122 void close() { | 122 void close() { |
123 _sink.close(); | 123 _sink.close(); |
124 } | 124 } |
125 | 125 |
126 void add(List<int> bytes) { | 126 void add(List<int> bytes) { |
127 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); | 127 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); |
128 } | 128 } |
129 } | 129 } |
OLD | NEW |