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

Side by Side Diff: sdk/lib/io/string_stream.dart

Issue 11446067: Revert "By default use current code page on Windows for decoding string" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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
« no previous file with comments | « sdk/lib/io/process.dart ('k') | utils/tests/pub/pub.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 abstract class _StringDecoder { 7 abstract class _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 26 matching lines...) Expand all
37 37
38 38
39 class _StringDecoders { 39 class _StringDecoders {
40 static _StringDecoder decoder(Encoding encoding) { 40 static _StringDecoder decoder(Encoding encoding) {
41 if (encoding == Encoding.UTF_8) { 41 if (encoding == Encoding.UTF_8) {
42 return new _UTF8Decoder(); 42 return new _UTF8Decoder();
43 } else if (encoding == Encoding.ISO_8859_1) { 43 } else if (encoding == Encoding.ISO_8859_1) {
44 return new _Latin1Decoder(); 44 return new _Latin1Decoder();
45 } else if (encoding == Encoding.ASCII) { 45 } else if (encoding == Encoding.ASCII) {
46 return new _AsciiDecoder(); 46 return new _AsciiDecoder();
47 } else if (encoding == Encoding.SYSTEM) {
48 if (Platform.operatingSystem == 'windows') {
49 return new _WindowsCodePageDecoder();
50 }
51 return new _UTF8Decoder();
52 } else { 47 } else {
53 if (encoding is Encoding) { 48 if (encoding is Encoding) {
54 throw new StreamException("Unsupported encoding ${encoding.name}"); 49 throw new StreamException("Unsupported encoding ${encoding.name}");
55 } else { 50 } else {
56 throw new StreamException("Unsupported encoding ${encoding}"); 51 throw new StreamException("Unsupported encoding ${encoding}");
57 } 52 }
58 } 53 }
59 } 54 }
60 } 55 }
61 56
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 bool _processNext() { 243 bool _processNext() {
249 while (_bufferList.length > 0) { 244 while (_bufferList.length > 0) {
250 int byte = _bufferList.next(); 245 int byte = _bufferList.next();
251 addChar(byte); 246 addChar(byte);
252 } 247 }
253 return true; 248 return true;
254 } 249 }
255 } 250 }
256 251
257 252
258 // Utility class for decoding Windows current code page data delivered
259 // as a stream of bytes.
260 class _WindowsCodePageDecoder extends _StringDecoderBase {
261 // Process the next chunk of data.
262 bool _processNext() {
263 List<int> bytes = _bufferList.readBytes(_bufferList.length);
264 for (var charCode in _decodeBytes(bytes).charCodes) {
265 addChar(charCode);
266 }
267 return true;
268 }
269
270 external static String _decodeBytes(List<int> bytes);
271 }
272
273
274 // Interface for encoders encoding string data into binary data. 253 // Interface for encoders encoding string data into binary data.
275 abstract class _StringEncoder { 254 abstract class _StringEncoder {
276 List<int> encodeString(String string); 255 List<int> encodeString(String string);
277 } 256 }
278 257
279 258
280 // Utility class for encoding a string into UTF-8 byte stream. 259 // Utility class for encoding a string into UTF-8 byte stream.
281 class _UTF8Encoder implements _StringEncoder { 260 class _UTF8Encoder implements _StringEncoder {
282 List<int> encodeString(String string) { 261 List<int> encodeString(String string) {
283 int size = _encodingSize(string); 262 int size = _encodingSize(string);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 throw new EncoderException( 306 throw new EncoderException(
328 "No ASCII encoding for code point $charCode"); 307 "No ASCII encoding for code point $charCode");
329 } 308 }
330 result[i] = charCode; 309 result[i] = charCode;
331 } 310 }
332 return result; 311 return result;
333 } 312 }
334 } 313 }
335 314
336 315
337 // Utility class for encoding a string into a current windows
338 // code page byte list.
339 class _WindowsCodePageEncoder implements _StringEncoder {
340 List<int> encodeString(String string) {
341 return _encodeString(string);
342 }
343
344 external static List<int> _encodeString(String string);
345 }
346
347
348 class _StringEncoders { 316 class _StringEncoders {
349 static _StringEncoder encoder(Encoding encoding) { 317 static _StringEncoder encoder(Encoding encoding) {
350 if (encoding == Encoding.UTF_8) { 318 if (encoding == Encoding.UTF_8) {
351 return new _UTF8Encoder(); 319 return new _UTF8Encoder();
352 } else if (encoding == Encoding.ISO_8859_1) { 320 } else if (encoding == Encoding.ISO_8859_1) {
353 return new _Latin1Encoder(); 321 return new _Latin1Encoder();
354 } else if (encoding == Encoding.ASCII) { 322 } else if (encoding == Encoding.ASCII) {
355 return new _AsciiEncoder(); 323 return new _AsciiEncoder();
356 } else if (encoding == Encoding.SYSTEM) {
357 if (Platform.operatingSystem == 'windows') {
358 return new _WindowsCodePageEncoder();
359 }
360 return new _UTF8Encoder();
361 } else { 324 } else {
362 throw new StreamException("Unsupported encoding ${encoding.name}"); 325 throw new StreamException("Unsupported encoding ${encoding.name}");
363 } 326 }
364 } 327 }
365 } 328 }
366 329
367 330
368 class EncoderException implements Exception { 331 class EncoderException implements Exception {
369 const EncoderException([String this.message]); 332 const EncoderException([String this.message]);
370 String toString() => "EncoderException: $message"; 333 String toString() => "EncoderException: $message";
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 bool _inputClosed = false; // Is the underlying input stream closed? 508 bool _inputClosed = false; // Is the underlying input stream closed?
546 bool _closed = false; // Is this stream closed. 509 bool _closed = false; // Is this stream closed.
547 bool _eof = false; // Has all data been read from the decoder? 510 bool _eof = false; // Has all data been read from the decoder?
548 Timer _scheduledDataCallback; 511 Timer _scheduledDataCallback;
549 Timer _scheduledLineCallback; 512 Timer _scheduledLineCallback;
550 Timer _scheduledCloseCallback; 513 Timer _scheduledCloseCallback;
551 Function _clientDataHandler; 514 Function _clientDataHandler;
552 Function _clientLineHandler; 515 Function _clientLineHandler;
553 Function _clientCloseHandler; 516 Function _clientCloseHandler;
554 } 517 }
OLDNEW
« no previous file with comments | « sdk/lib/io/process.dart ('k') | utils/tests/pub/pub.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698