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

Unified Diff: sdk/lib/_collection_dev/iterable.dart

Issue 18837002: Move toString() to collection classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reupload Created 7 years, 5 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 | « runtime/lib/typed_data.dart ('k') | sdk/lib/_internal/lib/js_array.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_collection_dev/iterable.dart
diff --git a/sdk/lib/_collection_dev/iterable.dart b/sdk/lib/_collection_dev/iterable.dart
index 82c6ebf12c6fb8300ba6bb17153e22e2de8d9d13..7013272c6ca420ddb7f99adf3b44859593143e73 100644
--- a/sdk/lib/_collection_dev/iterable.dart
+++ b/sdk/lib/_collection_dev/iterable.dart
@@ -688,6 +688,9 @@ abstract class BidirectionalIterator<T> implements Iterator<T> {
* The uses of this class will be replaced by mixins.
*/
class IterableMixinWorkaround {
+ // A list to identify cyclic collections during toString() calls.
+ static List _toStringList = new List();
+
static bool contains(Iterable iterable, var element) {
for (final e in iterable) {
if (e == element) return true;
@@ -881,6 +884,27 @@ class IterableMixinWorkaround {
return buffer.toString();
}
+ static String toStringIterable(Iterable iterable, String leftDelimiter,
+ String rightDelimiter) {
+ for (int i = 0; i < _toStringList.length; i++) {
+ if (identical(_toStringList[i], iterable)) {
+ return '$leftDelimiter...$rightDelimiter';
+ }
+ }
+
+ StringBuffer result = new StringBuffer();
+ try {
+ _toStringList.add(iterable);
+ result.write(leftDelimiter);
+ result.writeAll(iterable, ', ');
+ result.write(rightDelimiter);
+ } finally {
+ assert(identical(_toStringList.last, iterable));
+ _toStringList.removeLast();
+ }
+ return result.toString();
+ }
+
static Iterable where(Iterable iterable, bool f(var element)) {
return new WhereIterable(iterable, f);
}
« no previous file with comments | « runtime/lib/typed_data.dart ('k') | sdk/lib/_internal/lib/js_array.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698