Convert an Iterable
to a string like IterableBase.toString.
Allows using other delimiters than '(' and ')'.
Handles circular references where converting one of the elements to a string ends up converting iterable
to a string again.
static String iterableToShortString(Iterable iterable, [String leftDelimiter = '(', String rightDelimiter = ')']) { if (_isToStringVisiting(iterable)) { if (leftDelimiter == "(" && rightDelimiter == ")") { // Avoid creating a new string in the "common" case. return "(...)"; } return "$leftDelimiter...$rightDelimiter"; } List parts = []; _toStringVisiting.add(iterable); try { _iterablePartsToStrings(iterable, parts); } finally { assert(identical(_toStringVisiting.last, iterable)); _toStringVisiting.removeLast(); } return (new StringBuffer(leftDelimiter) ..writeAll(parts, ", ") ..write(rightDelimiter)) .toString(); }
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/2.0.0/dart-collection/IterableBase/iterableToShortString.html