iterableToFullString static method Null safety

String iterableToFullString(
  1. Iterable iterable,
  2. [String leftDelimiter = '(',
  3. String rightDelimiter = ')']
)

Converts an Iterable to a string.

Converts each elements to a string, and separates the results by ", ". Then wraps the result in leftDelimiter and rightDelimiter.

Unlike iterableToShortString, this conversion doesn't omit any elements or puts any limit on the size of the result.

Handles circular references where converting one of the elements to a string ends up converting iterable to a string again.

Implementation

static String iterableToFullString(Iterable iterable,
    [String leftDelimiter = '(', String rightDelimiter = ')']) {
  if (_isToStringVisiting(iterable)) {
    return "$leftDelimiter...$rightDelimiter";
  }
  StringBuffer buffer = StringBuffer(leftDelimiter);
  _toStringVisiting.add(iterable);
  try {
    buffer.writeAll(iterable, ", ");
  } finally {
    assert(identical(_toStringVisiting.last, iterable));
    _toStringVisiting.removeLast();
  }
  buffer.write(rightDelimiter);
  return buffer.toString();
}