| 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 part of dart.core; | 5 part of dart.core; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The StringBuffer class is useful for concatenating strings | 8 * The StringBuffer class is useful for concatenating strings |
| 9 * efficiently. Only on a call to [toString] are the strings | 9 * efficiently. Only on a call to [toString] are the strings |
| 10 * concatenated to a single String. | 10 * concatenated to a single String. |
| 11 */ | 11 */ |
| 12 class StringBuffer implements StringSink { | 12 class StringBuffer implements StringSink { |
| 13 | 13 |
| 14 /** Creates the string buffer with an initial content. */ | 14 /** Creates the string buffer with an initial content. */ |
| 15 external StringBuffer([Object content = ""]); | 15 external StringBuffer([Object content = ""]); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Returns the length of the content that has been accumulated so far. | 18 * Returns the length of the content that has been accumulated so far. |
| 19 * This is a constant-time operation. | 19 * This is a constant-time operation. |
| 20 */ | 20 */ |
| 21 external int get length; | 21 external int get length; |
| 22 | 22 |
| 23 /** Returns whether the buffer is empty. This is a constant-time operation. */ | 23 /** Returns whether the buffer is empty. This is a constant-time operation. */ |
| 24 bool get isEmpty => length == 0; | 24 bool get isEmpty => length == 0; |
| 25 | 25 |
| 26 /** |
| 27 * Returns whether the buffer is not empty. This is a constant-time |
| 28 * operation. |
| 29 */ |
| 30 bool get isNotEmpty => !isEmpty; |
| 31 |
| 26 /// Adds the contents of [obj], converted to a string, to the buffer. | 32 /// Adds the contents of [obj], converted to a string, to the buffer. |
| 27 external void write(Object obj); | 33 external void write(Object obj); |
| 28 | 34 |
| 29 /// Adds the string representation of [charCode] to the buffer. | 35 /// Adds the string representation of [charCode] to the buffer. |
| 30 external void writeCharCode(int charCode); | 36 external void writeCharCode(int charCode); |
| 31 | 37 |
| 32 void writeAll(Iterable objects, [String separator = ""]) { | 38 void writeAll(Iterable objects, [String separator = ""]) { |
| 33 Iterator iterator = objects.iterator; | 39 Iterator iterator = objects.iterator; |
| 34 if (!iterator.moveNext()) return; | 40 if (!iterator.moveNext()) return; |
| 35 if (separator.isEmpty) { | 41 if (separator.isEmpty) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 } | 57 } |
| 52 | 58 |
| 53 /** | 59 /** |
| 54 * Clears the string buffer. | 60 * Clears the string buffer. |
| 55 */ | 61 */ |
| 56 external void clear(); | 62 external void clear(); |
| 57 | 63 |
| 58 /// Returns the contents of buffer as a concatenated string. | 64 /// Returns the contents of buffer as a concatenated string. |
| 59 external String toString(); | 65 external String toString(); |
| 60 } | 66 } |
| OLD | NEW |