| 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 abstract class StringBuffer { | 10 abstract class StringBuffer { |
| 11 /** | 11 /** |
| 12 * Creates the string buffer with an initial content. | 12 * Creates the string buffer with an initial content. |
| 13 */ | 13 */ |
| 14 factory StringBuffer([Object content = ""]) | 14 factory StringBuffer([Object content = ""]) |
| 15 => new _StringBufferImpl(content); | 15 => new _StringBufferImpl(content); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Returns the length of the buffer. | 18 * Returns the length of the buffer. |
| 19 */ | 19 */ |
| 20 int get length; | 20 int get length; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Returns whether the buffer is empty. | 23 * Returns whether the buffer is empty. |
| 24 */ | 24 */ |
| 25 bool isEmpty(); | 25 bool get isEmpty; |
| 26 | 26 |
| 27 /** | 27 /** |
| 28 * Converts [obj] to a string and adds it to the buffer. Returns [:this:]. | 28 * Converts [obj] to a string and adds it to the buffer. Returns [:this:]. |
| 29 */ | 29 */ |
| 30 StringBuffer add(Object obj); | 30 StringBuffer add(Object obj); |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Adds the string representation of [charCode] to the buffer. | 33 * Adds the string representation of [charCode] to the buffer. |
| 34 * Returns [this]. | 34 * Returns [this]. |
| 35 */ | 35 */ |
| (...skipping 24 matching lines...) Expand all Loading... |
| 60 add(content); | 60 add(content); |
| 61 } | 61 } |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * Returns the length of the buffer. | 64 * Returns the length of the buffer. |
| 65 */ | 65 */ |
| 66 int get length { | 66 int get length { |
| 67 return _length; | 67 return _length; |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool isEmpty() { | 70 bool get isEmpty { |
| 71 return _length === 0; | 71 return _length === 0; |
| 72 } | 72 } |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Adds [obj] to the buffer. Returns [this]. | 75 * Adds [obj] to the buffer. Returns [this]. |
| 76 */ | 76 */ |
| 77 StringBuffer add(Object obj) { | 77 StringBuffer add(Object obj) { |
| 78 String str = obj.toString(); | 78 String str = obj.toString(); |
| 79 if (str === null || str.isEmpty()) { | 79 if (str === null || str.isEmpty) { |
| 80 return this; | 80 return this; |
| 81 } | 81 } |
| 82 _buffer.add(str); | 82 _buffer.add(str); |
| 83 _length += str.length; | 83 _length += str.length; |
| 84 return this; | 84 return this; |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Adds all items in [objects] to the buffer. Returns [this]. | 88 * Adds all items in [objects] to the buffer. Returns [this]. |
| 89 */ | 89 */ |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 _buffer.clear(); | 121 _buffer.clear(); |
| 122 _buffer.add(result); | 122 _buffer.add(result); |
| 123 // Since we track the length at each add operation, there is no | 123 // Since we track the length at each add operation, there is no |
| 124 // need to update it in this function. | 124 // need to update it in this function. |
| 125 return result; | 125 return result; |
| 126 } | 126 } |
| 127 | 127 |
| 128 List<String> _buffer; | 128 List<String> _buffer; |
| 129 int _length; | 129 int _length; |
| 130 } | 130 } |
| OLD | NEW |