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

Side by Side Diff: dart/sdk/lib/core/string_buffer.dart

Issue 11618037: Make StringBuffer and interpolation behave the same. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased and addressed review comments Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | dart/tests/language/string_interpolation_and_buffer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 add(content); 47 add(content);
48 } 48 }
49 49
50 /// Returns the length of the buffer. 50 /// Returns the length of the buffer.
51 int get length => _length; 51 int get length => _length;
52 52
53 bool get isEmpty => _length == 0; 53 bool get isEmpty => _length == 0;
54 54
55 /// Adds [obj] to the buffer. 55 /// Adds [obj] to the buffer.
56 void add(Object obj) { 56 void add(Object obj) {
57 // TODO(srdjan): The following four lines could be replaced by
58 // '$obj', but apparently this is too slow on the Dart VM.
57 String str = obj.toString(); 59 String str = obj.toString();
58 if (str == null || str.isEmpty) return; 60 if (str is !String) {
61 throw new ArgumentError('toString() did not return a string');
62 }
63 if (str.isEmpty) return;
59 _buffer.add(str); 64 _buffer.add(str);
60 _length += str.length; 65 _length += str.length;
61 } 66 }
62 67
63 /// Adds all items in [objects] to the buffer. 68 /// Adds all items in [objects] to the buffer.
64 void addAll(Collection objects) { 69 void addAll(Collection objects) {
65 for (Object obj in objects) add(obj); 70 for (Object obj in objects) add(obj);
66 } 71 }
67 72
68 /// Adds the string representation of [charCode] to the buffer. 73 /// Adds the string representation of [charCode] to the buffer.
(...skipping 12 matching lines...) Expand all
81 if (_buffer.length == 0) return ""; 86 if (_buffer.length == 0) return "";
82 if (_buffer.length == 1) return _buffer[0]; 87 if (_buffer.length == 1) return _buffer[0];
83 String result = Strings.concatAll(_buffer); 88 String result = Strings.concatAll(_buffer);
84 _buffer.clear(); 89 _buffer.clear();
85 _buffer.add(result); 90 _buffer.add(result);
86 // Since we track the length at each add operation, there is no 91 // Since we track the length at each add operation, there is no
87 // need to update it in this function. 92 // need to update it in this function.
88 return result; 93 return result;
89 } 94 }
90 } 95 }
OLDNEW
« no previous file with comments | « no previous file | dart/tests/language/string_interpolation_and_buffer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698