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

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: Addressed review comments. 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
Index: sdk/lib/_collection_dev/iterable.dart
diff --git a/sdk/lib/_collection_dev/iterable.dart b/sdk/lib/_collection_dev/iterable.dart
index 6e1e5ecb7c1b79be349de5fd215359d8294a6b0e..51d069accb4e08c3859238dbd20d7d6a9a687453 100644
--- a/sdk/lib/_collection_dev/iterable.dart
+++ b/sdk/lib/_collection_dev/iterable.dart
@@ -702,6 +702,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;
@@ -895,6 +898,44 @@ class IterableMixinWorkaround {
return buffer.toString();
}
+ static String toStringIterable(Iterable iterable) {
+ for (int i = 0; i < _toStringList.length; i++) {
+ if (identical(_toStringList[i], iterable)) { return '{...}'; }
+ }
+
+ StringBuffer result = new StringBuffer();
+ try {
+ _toStringList.add(iterable);
+ result.write('{');
+ result.writeAll(iterable, ', ');
+ result.write('}');
+ } finally {
+ assert(identical(_toStringList.last, iterable));
+ _toStringList.removeLast();
+
Lasse Reichstein Nielsen 2013/07/09 06:15:44 Empty line added. Seems inconsistent. Consider rem
zarah 2013/07/09 08:20:54 Done.
+ }
+ return result.toString();
+ }
+
+ static String toStringList(List list) {
+ for (int i = 0; i < _toStringList.length; i++) {
+ if (identical(_toStringList[i], list)) { return '[...]'; }
+ }
+
+ StringBuffer result = new StringBuffer();
+ try {
+ _toStringList.add(list);
+ result.write('[');
+ result.writeAll(list, ', ');
+ result.write(']');
+ } finally {
+ assert(identical(_toStringList.last, list));
+ _toStringList.removeLast();
+ }
+
+ return result.toString();
+ }
Lasse Reichstein Nielsen 2013/07/09 06:15:44 These two methods look almost, but not entirely, c
zarah 2013/07/09 08:20:54 Done.
+
static Iterable where(Iterable iterable, bool f(var element)) {
return new WhereIterable(iterable, f);
}

Powered by Google App Engine
This is Rietveld 408576698