static Int64 _parseRadix()

in lib/src/int64.dart [65:104]


  static Int64 _parseRadix(String s, int radix) {
    int i = 0;
    bool negative = false;
    if (i < s.length && s[0] == '-') {
      negative = true;
      i++;
    }

    // TODO(https://github.com/dart-lang/sdk/issues/38728). Replace with "if (i
    // >= s.length)".
    if (!(i < s.length)) {
      throw FormatException("No digits in '$s'");
    }

    int d0 = 0, d1 = 0, d2 = 0; //  low, middle, high components.
    for (; i < s.length; i++) {
      int c = s.codeUnitAt(i);
      int digit = Int32._decodeDigit(c);
      if (digit < 0 || digit >= radix) {
        throw FormatException('Non-radix char code: $c');
      }

      // [radix] and [digit] are at most 6 bits, component is 22, so we can
      // multiply and add within 30 bit temporary values.
      d0 = d0 * radix + digit;
      int carry = d0 >> _BITS;
      d0 = _MASK & d0;

      d1 = d1 * radix + carry;
      carry = d1 >> _BITS;
      d1 = _MASK & d1;

      d2 = d2 * radix + carry;
      d2 = _MASK2 & d2;
    }

    if (negative) return _negate(d0, d1, d2);

    return Int64._masked(d0, d1, d2);
  }