decimalValues function

List<int> decimalValues(
  1. String input, [
  2. int start = 0,
  3. int? end
])

The values of input's characters from start to end (exclusive, the whole string when omitted), ready for Digits.tryFrom.

The range is read straight off the code units, so a validated whole can hand back a digits-only part without allocating a substring. A non-digit yields -1, as decimalValue does, so Digits.tryFrom returns null rather than minting something that lies.

Implementation

List<int> decimalValues(String input, [int start = 0, int? end]) => [
  for (var index = start; index < (end ?? input.length); index++)
    decimalValue(input.codeUnitAt(index)),
];