getMajorMinorVersion static method

String getMajorMinorVersion(
  1. String version
)

Gets the major and minor version numbers from a version string. For details about the syntax of the input version. E.g., from x.y.z return x.y.

@param version The complete version string. @return A string of the form major.minor containing only the major and minor components of the version string.

Implementation

static String getMajorMinorVersion(String version) {
  final firstDot = version.indexOf('.');
  final secondDot = firstDot >= 0 ? version.indexOf('.', firstDot + 1) : -1;
  final firstDash = version.indexOf('-');
  var referenceLength = version.length;
  if (secondDot >= 0) {
    referenceLength = math.min(referenceLength, secondDot);
  }

  if (firstDash >= 0) {
    referenceLength = math.min(referenceLength, firstDash);
  }

  return version.substring(0, referenceLength);
}