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 static const int _BUFFER_SIZE = 64; | 6 static const int _BUFFER_SIZE = 64; |
7 static const int _PARTS_TO_COMPACT = 128; | 7 static const int _PARTS_TO_COMPACT = 128; |
8 static const int _PARTS_TO_COMPACT_SIZE_LIMIT = _PARTS_TO_COMPACT * 8; | 8 static const int _PARTS_TO_COMPACT_SIZE_LIMIT = _PARTS_TO_COMPACT * 8; |
9 | 9 |
10 /** | 10 /** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 int _bufferCodeUnitMagnitude = 0; | 48 int _bufferCodeUnitMagnitude = 0; |
49 | 49 |
50 /// Creates the string buffer with an initial content. | 50 /// Creates the string buffer with an initial content. |
51 /* patch */ StringBuffer([Object content = ""]) { | 51 /* patch */ StringBuffer([Object content = ""]) { |
52 write(content); | 52 write(content); |
53 } | 53 } |
54 | 54 |
55 /* patch */ int get length => _partsCodeUnits + _bufferPosition; | 55 /* patch */ int get length => _partsCodeUnits + _bufferPosition; |
56 | 56 |
57 /* patch */ void write(Object obj) { | 57 /* patch */ void write(Object obj) { |
58 String str; | 58 String str = '$obj'; |
59 if (obj is String) { | |
60 str = obj; | |
61 } else { | |
62 // TODO(srdjan): The following four lines could be replaced by | |
63 // '$obj', but apparently this is too slow on the Dart VM. | |
64 str = obj.toString(); | |
65 if (str is! String) { | |
66 throw new ArgumentError('toString() did not return a string'); | |
67 } | |
68 } | |
69 if (str.isEmpty) return; | 59 if (str.isEmpty) return; |
70 _consumeBuffer(); | 60 _consumeBuffer(); |
71 _addPart(str); | 61 _addPart(str); |
72 } | 62 } |
73 | 63 |
74 /* patch */ void writeCharCode(int charCode) { | 64 /* patch */ void writeCharCode(int charCode) { |
75 if (charCode <= 0xFFFF) { | 65 if (charCode <= 0xFFFF) { |
76 if (charCode < 0) { | 66 if (charCode < 0) { |
77 throw new RangeError.range(charCode, 0, 0x10FFFF); | 67 throw new RangeError.range(charCode, 0, 0x10FFFF); |
78 } | 68 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 _partsCodeUnitsSinceCompaction = 0; | 175 _partsCodeUnitsSinceCompaction = 0; |
186 _partsCompactionIndex = _parts.length; | 176 _partsCompactionIndex = _parts.length; |
187 } | 177 } |
188 | 178 |
189 /** | 179 /** |
190 * Create a [String] from the UFT-16 code units in buffer. | 180 * Create a [String] from the UFT-16 code units in buffer. |
191 */ | 181 */ |
192 static String _create(Uint16List buffer, int length, bool isLatin1) | 182 static String _create(Uint16List buffer, int length, bool isLatin1) |
193 native "StringBuffer_createStringFromUint16Array"; | 183 native "StringBuffer_createStringFromUint16Array"; |
194 } | 184 } |
OLD | NEW |