appendAlphanumericBytes static method

void appendAlphanumericBytes(
  1. String content,
  2. BitArray bits
)

Implementation

static void appendAlphanumericBytes(String content, BitArray bits) {
  final length = content.length;
  int i = 0;
  while (i < length) {
    final code1 = getAlphanumericCode(content.codeUnitAt(i));
    if (code1 == -1) {
      throw WriterException();
    }
    if (i + 1 < length) {
      final code2 = getAlphanumericCode(content.codeUnitAt(i + 1));
      if (code2 == -1) {
        throw WriterException();
      }
      // Encode two alphanumeric letters in 11 bits.
      bits.appendBits(code1 * 45 + code2, 11);
      i += 2;
    } else {
      // Encode one alphanumeric letter in six bits.
      bits.appendBits(code1, 6);
      i++;
    }
  }
}