| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 class StringBuffer { | |
| 6 | |
| 7 // Constructor. Optional argument [content] takes initial content. | |
| 8 StringBuffer([String content = ""]) { | |
| 9 init(content); | |
| 10 } | |
| 11 | |
| 12 // Returns the length of the buffer. | |
| 13 int get length() { | |
| 14 return length_; | |
| 15 } | |
| 16 | |
| 17 // Appends item to the buffer. | |
| 18 void append(String str) { | |
| 19 list_.add(str); | |
| 20 length_ += str.length; | |
| 21 } | |
| 22 | |
| 23 // Appends all items in strings to the buffer. | |
| 24 void appendAll(Collection<String> strings) { | |
| 25 strings.forEach((str) { append(str); }); | |
| 26 } | |
| 27 | |
| 28 // Clears the string buffer. | |
| 29 void clear() { | |
| 30 list_ = []; | |
| 31 length_ = 0; | |
| 32 } | |
| 33 | |
| 34 // Sets contents of buffer to str. | |
| 35 void init(String str) { | |
| 36 if (str.isEmpty()) { | |
| 37 clear(); | |
| 38 } else { | |
| 39 list_ = [str]; | |
| 40 length_ += str.length; | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 // Returns contents of buffer as a concatenated string. | |
| 45 String toString() { | |
| 46 String result = String.join(list_, ""); | |
| 47 list_ = [result]; | |
| 48 return result; | |
| 49 } | |
| 50 | |
| 51 List list_; | |
| 52 int length_; | |
| 53 } | |
| OLD | NEW |