readHex method

int readHex([
  1. int? hexLength
])

Implementation

int readHex([int? hexLength]) {
  int maxIndex;
  if (hexLength == null) {
    maxIndex = _text.length - 1;
  } else {
    // TODO(jimhug): What if this is too long?
    maxIndex = _index + hexLength;
    if (maxIndex >= _text.length) return -1;
  }
  var result = 0;
  while (_index < maxIndex) {
    final digit = _hexDigit(_text.codeUnitAt(_index));
    if (digit == -1) {
      if (hexLength == null) {
        return result;
      } else {
        return -1;
      }
    }
    _hexDigit(_text.codeUnitAt(_index));
    // Multiply by 16 rather than shift by 4 since that will result in a
    // correct value for numbers that exceed the 32 bit precision of JS
    // 'integers'.
    // TODO: Figure out a better solution to integer truncation. Issue 638.
    result = (result * 16) + digit;
    _index++;
  }

  return result;
}