addBinaryShiftChar method

State addBinaryShiftChar(
  1. int index
)

Implementation

State addBinaryShiftChar(int index) {
  Token token = _token;
  HighLevelEncoderMode mode = _mode;
  int bitCount = _bitCount;
  if (_mode == HighLevelEncoderMode.punct ||
      _mode == HighLevelEncoderMode.digit) {
    //assert binaryShiftByteCount == 0;
    final int latch = HighLevelEncoder.latchTable[mode.index]
        [HighLevelEncoderMode.upper.index];
    token = token.add(latch & 0xFFFF, latch >> 16);
    bitCount += latch >> 16;
    mode = HighLevelEncoderMode.upper;
  }
  final int deltaBitCount =
      (_binaryShiftByteCount == 0 || _binaryShiftByteCount == 31)
          ? 18
          : (_binaryShiftByteCount == 62)
              ? 9
              : 8;
  State result = State(
    token,
    mode,
    _binaryShiftByteCount + 1,
    bitCount + deltaBitCount,
  );
  if (result._binaryShiftByteCount == 2047 + 31) {
    // The string is as long as it's allowed to be.  We should end it.
    result = result.endBinaryShift(index + 1);
  }
  return result;
}