Spec-Zone.ru › Dart 2

dart:collection

iterableToShortString static method

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

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.

Implementation

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<String> parts = <String>[];
  _toStringVisiting.add(iterable);
  try {
    _iterablePartsToStrings(iterable, parts);
  } finally {
    assert(identical(_toStringVisiting.last, iterable));
    _toStringVisiting.removeLast();
  }
  return (StringBuffer(leftDelimiter)
        ..writeAll(parts, ", ")
        ..write(rightDelimiter))
      .toString();
}

© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.19.6/dart-collection/IterableBase/iterableToShortString.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API