| 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 /** | 7 /** |
| 8 * String encodings. | 8 * String encodings. |
| 9 */ | 9 */ |
| 10 class Encoding { | 10 class Encoding { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 StringDecoder([Encoding encoding = Encoding.UTF_8, int replacementChar]) { | 38 StringDecoder([Encoding encoding = Encoding.UTF_8, int replacementChar]) { |
| 39 switch (encoding) { | 39 switch (encoding) { |
| 40 case Encoding.UTF_8: | 40 case Encoding.UTF_8: |
| 41 if (replacementChar == null) { | 41 if (replacementChar == null) { |
| 42 replacementChar = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT; | 42 replacementChar = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT; |
| 43 } | 43 } |
| 44 _decoder = new Utf8DecoderTransformer(replacementChar); | 44 _decoder = new Utf8DecoderTransformer(replacementChar); |
| 45 break; | 45 break; |
| 46 case Encoding.ASCII: | 46 case Encoding.ASCII: |
| 47 if (replacementChar == null) { | 47 if (replacementChar == null) { |
| 48 replacementChar = '?'.charCodeAt(0); | 48 replacementChar = '?'.codeUnitAt(0); |
| 49 } else if (replacementChar > 127) { | 49 } else if (replacementChar > 127) { |
| 50 throw new ArgumentError("Invalid replacement character for ASCII"); | 50 throw new ArgumentError("Invalid replacement character for ASCII"); |
| 51 } | 51 } |
| 52 _decoder = new _AsciiDecoder(replacementChar); | 52 _decoder = new _AsciiDecoder(replacementChar); |
| 53 break; | 53 break; |
| 54 case Encoding.ISO_8859_1: | 54 case Encoding.ISO_8859_1: |
| 55 if (replacementChar == null) { | 55 if (replacementChar == null) { |
| 56 replacementChar = '?'.charCodeAt(0); | 56 replacementChar = '?'.codeUnitAt(0); |
| 57 } else if (replacementChar > 255) { | 57 } else if (replacementChar > 255) { |
| 58 throw new ArgumentError( | 58 throw new ArgumentError( |
| 59 "Invalid replacement character for ISO_8859_1"); | 59 "Invalid replacement character for ISO_8859_1"); |
| 60 } | 60 } |
| 61 _decoder = new _Latin1Decoder(replacementChar); | 61 _decoder = new _Latin1Decoder(replacementChar); |
| 62 break; | 62 break; |
| 63 case Encoding.SYSTEM: | 63 case Encoding.SYSTEM: |
| 64 if (Platform.operatingSystem == "windows") { | 64 if (Platform.operatingSystem == "windows") { |
| 65 _decoder = new _WindowsCodePageDecoder(); | 65 _decoder = new _WindowsCodePageDecoder(); |
| 66 } else { | 66 } else { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 | 170 |
| 171 void handle(String data, bool isClosing) { | 171 void handle(String data, bool isClosing) { |
| 172 if (_carry != null) { | 172 if (_carry != null) { |
| 173 data = _carry.concat(data); | 173 data = _carry.concat(data); |
| 174 _carry = null; | 174 _carry = null; |
| 175 } | 175 } |
| 176 int startPos = 0; | 176 int startPos = 0; |
| 177 int pos = 0; | 177 int pos = 0; |
| 178 while (pos < data.length) { | 178 while (pos < data.length) { |
| 179 int skip = 0; | 179 int skip = 0; |
| 180 int char = data.charCodeAt(pos); | 180 int char = data.codeUnitAt(pos); |
| 181 if (char == _LF) { | 181 if (char == _LF) { |
| 182 skip = 1; | 182 skip = 1; |
| 183 } else if (char == _CR) { | 183 } else if (char == _CR) { |
| 184 skip = 1; | 184 skip = 1; |
| 185 if (pos + 1 < data.length) { | 185 if (pos + 1 < data.length) { |
| 186 if (data.charCodeAt(pos + 1) == _LF) { | 186 if (data.codeUnitAt(pos + 1) == _LF) { |
| 187 skip = 2; | 187 skip = 2; |
| 188 } | 188 } |
| 189 } else if (!isClosing) { | 189 } else if (!isClosing) { |
| 190 _carry = data.substring(startPos); | 190 _carry = data.substring(startPos); |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 if (skip > 0) { | 194 if (skip > 0) { |
| 195 _buffer.add(data.substring(startPos, pos)); | 195 _buffer.add(data.substring(startPos, pos)); |
| 196 _controller.add(_buffer.toString()); | 196 _controller.add(_buffer.toString()); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 if (!_controller.hasSubscribers) { | 338 if (!_controller.hasSubscribers) { |
| 339 _subscription.cancel(); | 339 _subscription.cancel(); |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 | 343 |
| 344 | 344 |
| 345 // Utility class for encoding a string into an ASCII byte stream. | 345 // Utility class for encoding a string into an ASCII byte stream. |
| 346 class _AsciiEncoder extends _SingleByteEncoder { | 346 class _AsciiEncoder extends _SingleByteEncoder { |
| 347 List<int> _encode(String string) { | 347 List<int> _encode(String string) { |
| 348 var bytes = string.charCodes; | 348 var bytes = string.codeUnits; |
| 349 for (var byte in bytes) { | 349 for (var byte in bytes) { |
| 350 if (byte > 127) return null; | 350 if (byte > 127) return null; |
| 351 } | 351 } |
| 352 return bytes; | 352 return bytes; |
| 353 } | 353 } |
| 354 } | 354 } |
| 355 | 355 |
| 356 | 356 |
| 357 // Utility class for encoding a string into a Latin1 byte stream. | 357 // Utility class for encoding a string into a Latin1 byte stream. |
| 358 class _Latin1Encoder extends _SingleByteEncoder { | 358 class _Latin1Encoder extends _SingleByteEncoder { |
| 359 List<int> _encode(String string) { | 359 List<int> _encode(String string) { |
| 360 var bytes = string.charCodes; | 360 var bytes = string.codeUnits; |
| 361 for (var byte in bytes) { | 361 for (var byte in bytes) { |
| 362 if (byte > 255) return null; | 362 if (byte > 255) return null; |
| 363 } | 363 } |
| 364 return bytes; | 364 return bytes; |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 | 368 |
| 369 // Utility class for encoding a string into a current windows | 369 // Utility class for encoding a string into a current windows |
| 370 // code page byte list. | 370 // code page byte list. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 _subscription.resume(); | 405 _subscription.resume(); |
| 406 } | 406 } |
| 407 } | 407 } |
| 408 | 408 |
| 409 void _subscriptionChanged() { | 409 void _subscriptionChanged() { |
| 410 if (!_controller.hasSubscribers) { | 410 if (!_controller.hasSubscribers) { |
| 411 _subscription.cancel(); | 411 _subscription.cancel(); |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 } | 414 } |
| OLD | NEW |