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

Unified Diff: lib/core/string_buffer.dart

Issue 11274007: Move StringBufferImpl from coreimpl to core as _StringBufferImpl. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mark test as 'working'. Created 8 years, 2 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
« no previous file with comments | « no previous file | lib/coreimpl/coreimpl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/core/string_buffer.dart
diff --git a/lib/core/string_buffer.dart b/lib/core/string_buffer.dart
index 8095f6a0c367a3b05ade9b494bd9ca36ec1fba57..d56b3a3c7ffd2622595d95046da4979fa03cc144 100644
--- a/lib/core/string_buffer.dart
+++ b/lib/core/string_buffer.dart
@@ -11,7 +11,8 @@ abstract class StringBuffer {
/**
* Creates the string buffer with an initial content.
*/
- factory StringBuffer([Object content = ""]) => new StringBufferImpl(content);
+ factory StringBuffer([Object content = ""])
+ => new _StringBufferImpl(content);
/**
* Returns the length of the buffer.
@@ -49,3 +50,81 @@ abstract class StringBuffer {
*/
String toString();
}
+
+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 objects) {
+ 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 = StringImplementation.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 | « no previous file | lib/coreimpl/coreimpl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698