appendNumericBytes static method

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

Implementation

static void appendNumericBytes(String content, BitArray bits) {
  final length = content.length;
  int i = 0;
  while (i < length) {
    final num1 = content.codeUnitAt(i) - 48 /* 0 */;
    if (i + 2 < length) {
      // Encode three numeric letters in ten bits.
      final num2 = content.codeUnitAt(i + 1) - 48 /* 0 */;
      final num3 = content.codeUnitAt(i + 2) - 48 /* 0 */;
      bits.appendBits(num1 * 100 + num2 * 10 + num3, 10);
      i += 3;
    } else if (i + 1 < length) {
      // Encode two numeric letters in seven bits.
      final num2 = content.codeUnitAt(i + 1) - 48 /* 0 */;
      bits.appendBits(num1 * 10 + num2, 7);
      i += 2;
    } else {
      // Encode one numeric letter in four bits.
      bits.appendBits(num1, 4);
      i++;
    }
  }
}