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

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

Issue 11411092: Revert "Add some support for the code-point code-unit distinction." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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/core/string.dart ('k') | sdk/lib/uri/encode_decode.dart » ('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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 List<int> result = new Uint8List(size); 263 List<int> result = new Uint8List(size);
264 _encodeString(string, result); 264 _encodeString(string, result);
265 return result; 265 return result;
266 } 266 }
267 267
268 static int _encodingSize(String string) => _encodeString(string, null); 268 static int _encodingSize(String string) => _encodeString(string, null);
269 269
270 static int _encodeString(String string, List<int> buffer) { 270 static int _encodeString(String string, List<int> buffer) {
271 int pos = 0; 271 int pos = 0;
272 int length = string.length; 272 int length = string.length;
273 // TODO(erikcorry): Use new iterator over charcodes.
274 for (int i = 0; i < length; i++) { 273 for (int i = 0; i < length; i++) {
275 int additionalBytes; 274 int additionalBytes;
276 int charCode = string.charCodeAt(i); 275 int charCode = string.charCodeAt(i);
277 if (charCode <= 0x007F) { 276 if (charCode <= 0x007F) {
278 additionalBytes = 0; 277 additionalBytes = 0;
279 if (buffer != null) buffer[pos] = charCode; 278 if (buffer != null) buffer[pos] = charCode;
280 } else if (charCode <= 0x07FF) { 279 } else if (charCode <= 0x07FF) {
281 // 110xxxxx (xxxxx is top 5 bits). 280 // 110xxxxx (xxxxx is top 5 bits).
282 if (buffer != null) buffer[pos] = ((charCode >> 6) & 0x1F) | 0xC0; 281 if (buffer != null) buffer[pos] = ((charCode >> 6) & 0x1F) | 0xC0;
283 additionalBytes = 1; 282 additionalBytes = 1;
284 } else if (charCode <= 0xFFFF) { 283 } else if (charCode <= 0xFFFF) {
285 // 1110xxxx (xxxx is top 4 bits) 284 // 1110xxxx (xxxx is top 4 bits)
286 if (buffer != null) buffer[pos] = ((charCode >> 12) & 0x0F)| 0xE0; 285 if (buffer != null) buffer[pos] = ((charCode >> 12) & 0x0F)| 0xE0;
287 additionalBytes = 2; 286 additionalBytes = 2;
288 } else { 287 } else {
289 i++; // Skip surrogate pair.
290 // 11110xxx (xxx is top 3 bits) 288 // 11110xxx (xxx is top 3 bits)
291 if (buffer != null) buffer[pos] = ((charCode >> 18) & 0x07) | 0xF0; 289 if (buffer != null) buffer[pos] = ((charCode >> 18) & 0x07) | 0xF0;
292 additionalBytes = 3; 290 additionalBytes = 3;
293 } 291 }
294 pos++; 292 pos++;
295 if (buffer != null) { 293 if (buffer != null) {
296 for (int i = additionalBytes; i > 0; i--) { 294 for (int i = additionalBytes; i > 0; i--) {
297 // 10xxxxxx (xxxxxx is next 6 bits from the top). 295 // 10xxxxxx (xxxxxx is next 6 bits from the top).
298 buffer[pos++] = ((charCode >> (6 * (i - 1))) & 0x3F) | 0x80; 296 buffer[pos++] = ((charCode >> (6 * (i - 1))) & 0x3F) | 0x80;
299 } 297 }
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 bool _inputClosed = false; // Is the underlying input stream closed? 533 bool _inputClosed = false; // Is the underlying input stream closed?
536 bool _closed = false; // Is this stream closed. 534 bool _closed = false; // Is this stream closed.
537 bool _eof = false; // Has all data been read from the decoder? 535 bool _eof = false; // Has all data been read from the decoder?
538 Timer _scheduledDataCallback; 536 Timer _scheduledDataCallback;
539 Timer _scheduledLineCallback; 537 Timer _scheduledLineCallback;
540 Timer _scheduledCloseCallback; 538 Timer _scheduledCloseCallback;
541 Function _clientDataHandler; 539 Function _clientDataHandler;
542 Function _clientLineHandler; 540 Function _clientLineHandler;
543 Function _clientCloseHandler; 541 Function _clientCloseHandler;
544 } 542 }
OLDNEW
« no previous file with comments | « sdk/lib/core/string.dart ('k') | sdk/lib/uri/encode_decode.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698