2020-10-26 20:05:18 +03:00
|
|
|
module semver
|
|
|
|
|
|
|
|
// * Private functions.
|
|
|
|
[inline]
|
|
|
|
fn is_version_valid(input string) bool {
|
|
|
|
raw_ver := parse(input)
|
|
|
|
return raw_ver.is_valid()
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2023-03-02 16:49:50 +03:00
|
|
|
fn coerce_version(input string) !Version {
|
2020-10-26 20:05:18 +03:00
|
|
|
raw_ver := parse(input)
|
2023-05-27 01:57:02 +03:00
|
|
|
return raw_ver.coerce() or { return error('Invalid version for input "${input}"') }
|
2020-10-26 20:05:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
|
|
|
fn increment_version(ver Version, typ Increment) Version {
|
|
|
|
mut major := ver.major
|
|
|
|
mut minor := ver.minor
|
|
|
|
mut patch := ver.patch
|
|
|
|
match typ {
|
|
|
|
.major {
|
|
|
|
major++
|
|
|
|
minor = 0
|
|
|
|
patch = 0
|
|
|
|
}
|
|
|
|
.minor {
|
|
|
|
minor++
|
|
|
|
patch = 0
|
|
|
|
}
|
|
|
|
.patch {
|
|
|
|
patch++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Version{major, minor, patch, ver.prerelease, ver.metadata}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_valid_string(input string) bool {
|
|
|
|
for c in input {
|
|
|
|
if !(c.is_letter() || c.is_digit() || c == `.` || c == `-`) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_valid_number(input string) bool {
|
|
|
|
for c in input {
|
|
|
|
if !c.is_digit() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|