Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: compiler/lib/implementation/string_buffer.dart

Issue 9865025: Revert "Removes dartc reliance on its own libraries, now can be targeted at any implementation's li… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: compiler/lib/implementation/string_buffer.dart
diff --git a/compiler/lib/implementation/string_buffer.dart b/compiler/lib/implementation/string_buffer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..373c78d37a1f851e0f7c80816bc7792285d9fad8
--- /dev/null
+++ b/compiler/lib/implementation/string_buffer.dart
@@ -0,0 +1,87 @@
+// 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.
+
+/**
+ * The StringBuffer class is useful for concatenating strings
+ * efficiently. Only on a call to [toString] are the strings
+ * concatenated to a single String.
+ */
+class StringBufferImpl implements StringBuffer {
+ /**
+ * Creates the string buffer with an initial content.
+ */
+ StringBufferImpl([Object content = ""]) {
+ clear();
+ add(content);
+ }
+
+ /**
+ * Returns the length of the buffer.
+ */
+ int get length() {
+ return _length;
+ }
+
+ bool isEmpty() {
+ return _length == 0;
+ }
+
+ /**
+ * Adds [obj] to the buffer. Returns [this].
+ */
+ StringBuffer add(Object obj) {
+ String str = obj.toString();
+ if (str === null || str.isEmpty()) return this;
+ _buffer.add(str);
+ _length += str.length;
+ return this;
+ }
+
+ /**
+ * Adds all items in [objects] to the buffer. Returns [this].
+ */
+ StringBuffer addAll(Collection<Object> objects) {
+ if (objects == null) {
+ throw const NullPointerException();
+ }
+ for (Object obj in objects) {
+ add(obj);
+ }
+ return this;
+ }
+
+ /**
+ * Adds the string representation of [charCode] to the buffer.
+ * Returns [this].
+ */
+ StringBuffer addCharCode(int charCode) {
+ return add(new String.fromCharCodes([charCode]));
+ }
+
+ /**
+ * Clears the string buffer. Returns [this].
+ */
+ StringBuffer clear() {
+ _buffer = new List<String>();
+ _length = 0;
+ return this;
+ }
+
+ /**
+ * Returns the contents of buffer as a concatenated string.
+ */
+ String toString() {
+ if (_buffer.length == 0) return "";
+ if (_buffer.length == 1) return _buffer[0];
+ String result = StringBase.concatAll(_buffer);
+ _buffer.clear();
+ _buffer.add(result);
+ // Since we track the length at each add operation, there is no
+ // need to update it in this function.
+ return result;
+ }
+
+ List<String> _buffer;
+ int _length;
+}
« no previous file with comments | « compiler/lib/implementation/string_base.dart ('k') | compiler/lib/implementation/time_zone_implementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698