Chromium Code Reviews| 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); |
| } |