| Index: runtime/lib/string_buffer_patch.dart
|
| diff --git a/runtime/lib/string_buffer_patch.dart b/runtime/lib/string_buffer_patch.dart
|
| index ac700bf3899dce6d6adad32d8802d26c5e9ce918..841fc4f884602dc757f697784a1615af28925f43 100644
|
| --- a/runtime/lib/string_buffer_patch.dart
|
| +++ b/runtime/lib/string_buffer_patch.dart
|
| @@ -2,45 +2,58 @@
|
| // 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.
|
|
|
| -patch class StringBuffer {
|
| +patch /* abstract */ class StringBuffer {
|
| + /* patch */ factory StringBuffer([Object content = ""])
|
| + => new _StringBufferImpl(content);
|
| +}
|
| +
|
| +class _StringBufferImpl implements StringBuffer {
|
| +
|
| List<String> _buffer;
|
| int _length;
|
|
|
| /// Creates the string buffer with an initial content.
|
| - /* patch */ StringBuffer([Object content = ""]) {
|
| - _buffer = new List<String>();
|
| - _length = 0;
|
| - write(content);
|
| + _StringBufferImpl(Object content) {
|
| + clear();
|
| + add(content);
|
| }
|
|
|
| - /* patch */ int get length => _length;
|
| + /// Returns the length of the buffer.
|
| + int get length => _length;
|
| +
|
| + bool get isEmpty => _length == 0;
|
|
|
| /// Adds [obj] to the buffer.
|
| - /* patch */ void write(Object obj) {
|
| + void add(Object obj) {
|
| // TODO(srdjan): The following four lines could be replaced by
|
| // '$obj', but apparently this is too slow on the Dart VM.
|
| - String str;
|
| - if (obj is String) {
|
| - str = obj;
|
| - } else {
|
| - str = obj.toString();
|
| - if (str is! String) {
|
| - throw new ArgumentError('toString() did not return a string');
|
| - }
|
| + String str = obj.toString();
|
| + if (str is !String) {
|
| + throw new ArgumentError('toString() did not return a string');
|
| }
|
| if (str.isEmpty) return;
|
| _buffer.add(str);
|
| _length += str.length;
|
| }
|
|
|
| + /// Adds all items in [objects] to the buffer.
|
| + void addAll(Iterable objects) {
|
| + for (Object obj in objects) add(obj);
|
| + }
|
| +
|
| + /// Adds the string representation of [charCode] to the buffer.
|
| + void addCharCode(int charCode) {
|
| + add(new String.fromCharCodes([charCode]));
|
| + }
|
| +
|
| /// Clears the string buffer.
|
| - /* patch */ void clear() {
|
| + void clear() {
|
| _buffer = new List<String>();
|
| _length = 0;
|
| }
|
|
|
| /// Returns the contents of buffer as a concatenated string.
|
| - /* patch */ String toString() {
|
| + String toString() {
|
| if (_buffer.length == 0) return "";
|
| if (_buffer.length == 1) return _buffer[0];
|
| String result = Strings.concatAll(_buffer);
|
|
|