parseVersion static method

double parseVersion(
  1. String version, {
  2. String separator = '.',
  3. bool twoDigits = false,
})

Parses the given version into a double.

  • twoDigits whether to interpret "16.3" as 16.03. If false (default), it is interpreted as 16.3.

Implementation

static double parseVersion(String version,
    {String separator='.', bool twoDigits = false}) {
    //=> not necessary until we'd like parse MacOS's version

  try {
    int j = version.indexOf(separator);
    if (j >= 0) {
      final k = version.indexOf(separator, ++j);
      if (k >= 0)
        version = version.substring(0, k);
      if (twoDigits && version.length == j + 1) //only one decimal, e.g., 12.3
        version = version.substring(0, j) + "0" + version.substring(j);
      if (separator != '.')
        version = version.replaceAll(separator, '.');
    }
    return double.parse(version);
  } catch (e) {
    return 1.0; //ignore it
  }
}