mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 17:04:56 +00:00
6467b4302d
Sometimes we can avoid the StringBuffer object: t1 = new P.StringBuffer(leftDelimiter); t1.writeAll$2(parts, ", "); t1 = t1._contents += rightDelimiter; return t1.charCodeAt(0) == 0 ? t1 : t1; --> t1 = P.StringBuffer__writeAll(leftDelimiter, parts, ", ") + rightDelimiter; return t1.charCodeAt(0) == 0 ? t1 : t1; Also updated tests with missing cases. R=lrn@google.com Committed: https://code.google.com/p/dart/source/detail?r=45184 Reverted: https://code.google.com/p/dart/source/detail?r=45186 Review URL: https://codereview.chromium.org//1086043002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45188 260f80e4-7a28-3924-810f-c04153c831b5
52 lines
1.5 KiB
Dart
52 lines
1.5 KiB
Dart
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
part of dart.core;
|
|
|
|
/**
|
|
* A class for concatenating strings efficiently.
|
|
*
|
|
* Allows for the incremental building of a string using write*() methods.
|
|
* The strings are concatenated to a single string only when [toString] is
|
|
* called.
|
|
*/
|
|
class StringBuffer implements StringSink {
|
|
|
|
/** Creates the string buffer with an initial content. */
|
|
external StringBuffer([Object content = ""]);
|
|
|
|
/**
|
|
* Returns the length of the content that has been accumulated so far.
|
|
* This is a constant-time operation.
|
|
*/
|
|
external int get length;
|
|
|
|
/** Returns whether the buffer is empty. This is a constant-time operation. */
|
|
bool get isEmpty => length == 0;
|
|
|
|
/**
|
|
* Returns whether the buffer is not empty. This is a constant-time
|
|
* operation.
|
|
*/
|
|
bool get isNotEmpty => !isEmpty;
|
|
|
|
/// Adds the contents of [obj], converted to a string, to the buffer.
|
|
external void write(Object obj);
|
|
|
|
/// Adds the string representation of [charCode] to the buffer.
|
|
external void writeCharCode(int charCode);
|
|
|
|
external void writeAll(Iterable objects, [String separator = ""]);
|
|
|
|
external void writeln([Object obj = ""]);
|
|
|
|
/**
|
|
* Clears the string buffer.
|
|
*/
|
|
external void clear();
|
|
|
|
/// Returns the contents of buffer as a concatenated string.
|
|
external String toString();
|
|
}
|