hasAttributionsWithin method

bool hasAttributionsWithin({
  1. required Set<Attribution> attributions,
  2. required int start,
  3. required int end,
})

Returns true if this AttributedSpans contains at least one unit of attribution for each of the given attributions within the given range (inclusive).

Implementation

bool hasAttributionsWithin({
  required Set<Attribution> attributions,
  required int start,
  required int end,
}) {
  final attributionsToFind = Set.from(attributions);
  for (int i = start; i <= end; ++i) {
    final foundAttributions = <Attribution>{};
    for (final attribution in attributionsToFind) {
      if (hasAttributionAt(i, attribution: attribution)) {
        // Store the attributions we found so far to remove them
        // from attributionsToFind after the loop.
        //
        // Removing from the set while iterating throws an exception.
        foundAttributions.add(attribution);
      }
    }
    attributionsToFind.removeAll(foundAttributions);
    if (attributionsToFind.isEmpty) {
      // We found all attributions.
      return true;
    }
  }
  return false;
}