parsePositiveInt function

int parsePositiveInt(
  1. String value
)

Parses a positive integer from the given value and returns it as an int.

  • Throws a FormatException if the value is empty, contains an invalid number, is negative, or is not an integer.

Implementation

int parsePositiveInt(final String value) {
  final int parsedValue = parseInt(value);
  if (parsedValue.isNegative) {
    throw const FormatException('Must be non-negative');
  }
  return parsedValue;
}