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. |
(...skipping 11 matching lines...) Expand all Loading... | |
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 /// Adds the contents of [obj], converted to a string, to the buffer. | 26 /// Adds the contents of [obj], converted to a string, to the buffer. |
27 external void write(Object obj); | 27 external void write(Object obj); |
28 | 28 |
29 /// Adds the string representation of [charCode] to the buffer. | 29 /// Adds the string representation of [charCode] to the buffer. |
30 external void writeCharCode(int charCode); | 30 external void writeCharCode(int charCode); |
31 | 31 |
32 void writeAll(Iterable objects) { | 32 void writeAll(Iterable objects, [String separator = ""]) { |
33 for (Object obj in objects) write(obj); | 33 bool isFirst = true; |
34 for (Object obj in objects) { | |
35 if (isFirst) { | |
36 isFirst = false; | |
37 } else { | |
38 if (separator != "") write(separator); | |
sra1
2013/03/22 21:19:46
Can we avoid this repeated test in the loop?
Or at
floitsch
2013/03/26 18:30:23
Done.
Lasse Reichstein Nielsen
2013/04/03 10:35:52
If speed is of the essence, I'd prefer:
void writ
floitsch
2013/04/04 22:36:36
I didn't use Stephen's suggestion but had a code t
| |
39 } | |
40 write(obj); | |
41 } | |
34 } | 42 } |
35 | 43 |
36 void writeln([Object obj = ""]) { | 44 void writeln([Object obj = ""]) { |
37 write(obj); | 45 write(obj); |
38 write("\n"); | 46 write("\n"); |
39 } | 47 } |
40 | 48 |
41 /** | 49 /** |
42 * Clears the string buffer. | 50 * Clears the string buffer. |
43 */ | 51 */ |
44 external void clear(); | 52 external void clear(); |
45 | 53 |
46 /// Returns the contents of buffer as a concatenated string. | 54 /// Returns the contents of buffer as a concatenated string. |
47 external String toString(); | 55 external String toString(); |
48 } | 56 } |
OLD | NEW |