blob: 142ce196dab5728852489181b6341269689a1840 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
module semver
// * Private functions.
[inline]
fn is_version_valid(input string) bool {
raw_ver := parse(input)
return raw_ver.is_valid()
}
[inline]
fn coerce_version(input string) ?Version {
raw_ver := parse(input)
ver := raw_ver.coerce() or { return error('Invalid version for input "$input"') }
return ver
}
[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
}
|