| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * The StringBuffer class is useful for concatenating strings | 6 * The StringBuffer class is useful for concatenating strings |
| 7 * efficiently. Only on a call to [toString] are the strings | 7 * efficiently. Only on a call to [toString] are the strings |
| 8 * concatenated to a single String. | 8 * concatenated to a single String. |
| 9 */ | 9 */ |
| 10 class StringBufferImpl implements StringBuffer { | 10 class StringBufferImpl implements StringBuffer { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 * Returns [this]. | 53 * Returns [this]. |
| 54 */ | 54 */ |
| 55 StringBuffer addCharCode(int charCode) { | 55 StringBuffer addCharCode(int charCode) { |
| 56 return add(new String.fromCharCodes([charCode])); | 56 return add(new String.fromCharCodes([charCode])); |
| 57 } | 57 } |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Clears the string buffer. Returns [this]. | 60 * Clears the string buffer. Returns [this]. |
| 61 */ | 61 */ |
| 62 StringBuffer clear() { | 62 StringBuffer clear() { |
| 63 _buffer = new Array<String>(); | 63 _buffer = new List<String>(); |
| 64 _length = 0; | 64 _length = 0; |
| 65 return this; | 65 return this; |
| 66 } | 66 } |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Returns the contents of buffer as a concatenated string. | 69 * Returns the contents of buffer as a concatenated string. |
| 70 */ | 70 */ |
| 71 String toString() { | 71 String toString() { |
| 72 if (_buffer.length == 0) return ""; | 72 if (_buffer.length == 0) return ""; |
| 73 if (_buffer.length == 1) return _buffer[0]; | 73 if (_buffer.length == 1) return _buffer[0]; |
| 74 String result = StringBase.concatAll(_buffer); | 74 String result = StringBase.concatAll(_buffer); |
| 75 _buffer.clear(); | 75 _buffer.clear(); |
| 76 _buffer.add(result); | 76 _buffer.add(result); |
| 77 // Since we track the length at each add operation, there is no | 77 // Since we track the length at each add operation, there is no |
| 78 // need to update it in this function. | 78 // need to update it in this function. |
| 79 return result; | 79 return result; |
| 80 } | 80 } |
| 81 | 81 |
| 82 Array<String> _buffer; | 82 List<String> _buffer; |
| 83 int _length; | 83 int _length; |
| 84 } | 84 } |
| OLD | NEW |