| OLD | NEW |
| 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 patch class StringBuffer { | 5 patch class StringBuffer { |
| 6 /** Backing store for collected UTF-16 code units. */ | 6 /** Backing store for collected UTF-16 code units. */ |
| 7 Uint16List _buffer; | 7 Uint16List _buffer; |
| 8 /** Number of code units collected. */ | 8 /** Number of code units collected. */ |
| 9 int _length = 0; | 9 int _length = 0; |
| 10 /** | 10 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 if (str.isEmpty) return; | 40 if (str.isEmpty) return; |
| 41 _ensureCapacity(str.length); | 41 _ensureCapacity(str.length); |
| 42 for (int i = 0; i < str.length; i++) { | 42 for (int i = 0; i < str.length; i++) { |
| 43 int unit = str.codeUnitAt(i); | 43 int unit = str.codeUnitAt(i); |
| 44 _buffer[_length + i] = unit; | 44 _buffer[_length + i] = unit; |
| 45 _codeUnitMagnitude |= unit; | 45 _codeUnitMagnitude |= unit; |
| 46 } | 46 } |
| 47 _length += str.length; | 47 _length += str.length; |
| 48 } | 48 } |
| 49 | 49 |
| 50 /* patch */ writeCharCode(int charCode) { | 50 /* patch */ void writeCharCode(int charCode) { |
| 51 if (charCode <= 0xFFFF) { | 51 if (charCode <= 0xFFFF) { |
| 52 if (charCode < 0) { | 52 if (charCode < 0) { |
| 53 throw new RangeError.range(charCode, 0, 0x10FFFF); | 53 throw new RangeError.range(charCode, 0, 0x10FFFF); |
| 54 } | 54 } |
| 55 _ensureCapacity(1); | 55 _ensureCapacity(1); |
| 56 _buffer[_length++] = charCode; | 56 _buffer[_length++] = charCode; |
| 57 _codeUnitMagnitude |= charCode; | 57 _codeUnitMagnitude |= charCode; |
| 58 } else { | 58 } else { |
| 59 if (charCode > 0x10FFFF) { | 59 if (charCode > 0x10FFFF) { |
| 60 throw new RangeError.range(charCode, 0, 0x10FFFF); | 60 throw new RangeError.range(charCode, 0, 0x10FFFF); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 newBuffer.setRange(0, _length, _buffer); | 98 newBuffer.setRange(0, _length, _buffer); |
| 99 _buffer = newBuffer; | 99 _buffer = newBuffer; |
| 100 } | 100 } |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Create a [String] from the UFT-16 code units in buffer. | 103 * Create a [String] from the UFT-16 code units in buffer. |
| 104 */ | 104 */ |
| 105 static String _create(Uint16List buffer, int length, bool isLatin1) | 105 static String _create(Uint16List buffer, int length, bool isLatin1) |
| 106 native "StringBuffer_createStringFromUint16Array"; | 106 native "StringBuffer_createStringFromUint16Array"; |
| 107 } | 107 } |
| OLD | NEW |