decimalToInt function Null safety

int decimalToInt(
  1. String text,
  2. int start,
  3. [List<int>? length,
  4. int? last]
)

Returns the int value of a decimal number in a text starting at index start. text: the string to inspect length: OUT: if not null: the count of digits will be stored in length0 last: if not null: the number detection ends with this index (excluding)

Implementation

int decimalToInt(String text, int start, [List<int>? length, int? last]) {
  var rc = 0;
  last ??= text.length;
  int digit;
  var len = 0;
  while (start < text.length && start < last) {
    if ((digit = text.codeUnitAt(start)) >= 0x30 && digit <= 0x39) {
      rc = rc * 10 + (digit - 0x30);
      ++len;
    } else {
      break;
    }
    ++start;
  }
  if (length != null) {
    length[0] = len;
  }
  return rc;
}