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 * Converts [obj] to a string and adds it to the buffer. | |
28 * | |
29 * *Deprecated*. Use [write] instead. | |
30 */ | |
31 @deprecated | |
32 void add(Object obj) => write(obj); | |
33 | |
34 external void write(Object obj); | 26 external void write(Object obj); |
35 | 27 |
36 void writeAll(Iterable objects) { | 28 void writeAll(Iterable objects) { |
37 for (Object obj in objects) write(obj); | 29 for (Object obj in objects) write(obj); |
38 } | 30 } |
39 | 31 |
40 void writeln(Object obj) { | 32 void writeln(Object obj) { |
41 write(obj); | 33 write(obj); |
42 write("\n"); | 34 write("\n"); |
43 } | 35 } |
44 | 36 |
45 /** | |
46 * Adds the string representation of [charCode] to the buffer. | |
47 * | |
48 * *Deprecated* Use [writeCharCode] instead. | |
49 */ | |
50 @deprecated | |
51 void addCharCode(int charCode) { | |
52 writeCharCode(charCode); | |
53 } | |
54 | |
55 /// Adds the string representation of [charCode] to the buffer. | 37 /// Adds the string representation of [charCode] to the buffer. |
56 void writeCharCode(int charCode) { | 38 void writeCharCode(int charCode) { |
57 write(new String.fromCharCode(charCode)); | 39 write(new String.fromCharCode(charCode)); |
58 } | 40 } |
59 | 41 |
60 /** | 42 /** |
61 * Adds all items in [objects] to the buffer. | |
62 * | |
63 * *Deprecated*. Use [writeAll] instead. | |
64 */ | |
65 @deprecated | |
66 void addAll(Iterable objects) { | |
67 for (Object obj in objects) write(obj); | |
68 } | |
69 | |
70 /** | |
71 * Clears the string buffer. | 43 * Clears the string buffer. |
72 * | 44 * |
73 * *Deprecated*. | 45 * *Deprecated*. |
74 */ | 46 */ |
75 @deprecated | 47 @deprecated |
76 external void clear(); | 48 external void clear(); |
77 | 49 |
78 /// Returns the contents of buffer as a concatenated string. | 50 /// Returns the contents of buffer as a concatenated string. |
79 external String toString(); | 51 external String toString(); |
80 } | 52 } |
OLD | NEW |