retrieveNextPair method

ExpandedPair? retrieveNextPair(
  1. BitArray row,
  2. List<ExpandedPair> previousPairs,
  3. int rowNumber
)

Implementation

ExpandedPair? retrieveNextPair(
  BitArray row,
  List<ExpandedPair> previousPairs,
  int rowNumber,
) {
  bool isOddPattern = previousPairs.length % 2 == 0;
  if (_startFromEven) {
    isOddPattern = !isOddPattern;
  }

  FinderPattern? pattern;

  bool keepFinding = true;
  int forcedOffset = -1;
  do {
    _findNextPair(row, previousPairs, forcedOffset);
    pattern = _parseFoundFinderPattern(
      row,
      rowNumber,
      isOddPattern,
      previousPairs,
    );
    if (pattern == null) {
      forcedOffset = _getNextSecondBar(row, _startEnd[0]);
    } else {
      keepFinding = false;
    }
  } while (keepFinding);

  // When stacked symbol is split over multiple rows, there's no way to guess if this pair can be last or not.
  // bool mayBeLast = checkPairSequence(previousPairs, pattern);

  final leftChar = decodeDataCharacter(row, pattern!, isOddPattern, true);

  if (previousPairs.isNotEmpty &&
      previousPairs[previousPairs.length - 1].mustBeLast) {
    throw NotFoundException.instance;
  }

  DataCharacter? rightChar;
  try {
    rightChar = decodeDataCharacter(row, pattern, isOddPattern, false);
  } on NotFoundException catch (_) {
    rightChar = null;
  }
  return ExpandedPair(leftChar, rightChar, pattern);
}