BaseConversion.alphabet constructor

BaseConversion.alphabet({
  1. required Alphabet from,
  2. required Alphabet to,
  3. bool zeroPadding = false,
})

Constructs a BaseConversion object with the given from and to alphabets.

Implementation

BaseConversion.alphabet({
  required Alphabet from,
  required Alphabet to,
  bool zeroPadding = false,
})  : _fromAlphabet = from,
      _toAlphabet = to,
      _lengthFactor = __lengthFactor(from: from, to: to),
      _intLengthFactor = (() {
        final double lengthFactor = __lengthFactor(from: from, to: to);
        int intLengthFactor = lengthFactor.truncate();
        if (lengthFactor == intLengthFactor) {
          return intLengthFactor;
        } else {
          final double invLengthFactor = (1 / lengthFactor);
          intLengthFactor = -invLengthFactor.truncate();
          if (invLengthFactor == -intLengthFactor) {
            return intLengthFactor;
          }
        }
        return 0;
      })(),
      _zeroPadding = zeroPadding;