stringToMajorMinor function

List<int> stringToMajorMinor(
  1. String s
)

Implementation

List<int> stringToMajorMinor(String s) {
  int pos = s.indexOf('.');
  if (pos == -1) {
    throw VersionParseException("malformed version value `$s'");
  }

  late int major, minor;

  try {
    major = int.tryParse(s.substring(0, pos))!;
  } catch (e) {
    throw VersionParseException("invalid major version value `$s'");
  }

  try {
    minor = int.tryParse(s.substring(pos + 1))!;
  } catch (e) {
    throw VersionParseException("invalid minor version value `$s'");
  }

  if (major < 1 || major > 255 || minor < 0 || minor > 255) {
    throw VersionParseException("range error in version `$s'");
  }

  return [major, minor];
}