incrementPreRelease method
Creates a new Version with the right-most numeric preRelease segment incremented. If no numeric segment is found, one will be added with the value "1".
If this Version is not a pre-release version, an Exception will be thrown.
Implementation
Version incrementPreRelease() {
if (!this.isPreRelease) {
throw Exception(
"Cannot increment pre-release on a non-pre-release [Version]");
}
var newPreRelease = this.preRelease;
var found = false;
for (var i = newPreRelease.length - 1; i >= 0; i--) {
var segment = newPreRelease[i];
if (Version._isNumeric(segment)) {
var intVal = int.parse(segment);
intVal++;
newPreRelease[i] = intVal.toString();
found = true;
break;
}
}
if (!found) {
newPreRelease.add("1");
}
return Version(this.major, this.minor, this.patch,
preRelease: newPreRelease);
}