@@ -39,7 +39,7 @@ extension SemanticVersion: LosslessStringConvertible {
39
39
40
40
41
41
extension SemanticVersion : Comparable {
42
- public static func < ( lhs: Self , rhs: Self ) -> Bool {
42
+ public static func < ( lhs: SemanticVersion , rhs: SemanticVersion ) -> Bool {
43
43
if lhs. major != rhs. major { return lhs. major < rhs. major }
44
44
if lhs. minor != rhs. minor { return lhs. minor < rhs. minor }
45
45
if lhs. patch != rhs. patch { return lhs. patch < rhs. patch }
@@ -57,17 +57,19 @@ extension SemanticVersion: Comparable {
57
57
58
58
59
59
extension SemanticVersion {
60
- public var isStable : Bool { preRelease. isEmpty && build. isEmpty }
61
- public var isPreRelease : Bool { !isStable }
62
- public var isMajorRelease : Bool { isStable && ( major > 0 && minor == 0 && patch == 0 ) }
63
- public var isMinorRelease : Bool { isStable && ( minor > 0 && patch == 0 ) }
64
- public var isPatchRelease : Bool { isStable && patch > 0 }
65
- public var isInitialRelease : Bool { self == . init( 0 , 0 , 0 ) }
60
+ public var isStable : Bool { return preRelease. isEmpty && build. isEmpty }
61
+ public var isPreRelease : Bool { return !isStable }
62
+ public var isMajorRelease : Bool { return isStable && ( major > 0 && minor == 0 && patch == 0 ) }
63
+ public var isMinorRelease : Bool { return isStable && ( minor > 0 && patch == 0 ) }
64
+ public var isPatchRelease : Bool { return isStable && patch > 0 }
65
+ public var isInitialRelease : Bool { return self == . init( 0 , 0 , 0 ) }
66
66
}
67
67
68
68
69
69
// Source: https://regex101.com/r/Ly7O1x/3/
70
70
// Linked from https://semver.org
71
+ #if swift(>=5)
72
+
71
73
let semVerRegex = NSRegularExpression ( #"""
72
74
^
73
75
v? # SPI extension: allow leading 'v'
@@ -91,3 +93,31 @@ v? # SPI extension: allow leading 'v'
91
93
)?
92
94
$
93
95
"""# , options: [ . allowCommentsAndWhitespace] )
96
+
97
+ #else
98
+
99
+ let semVerRegex = NSRegularExpression ( """
100
+ ^
101
+ v? # SPI extension: allow leading 'v'
102
+ (?<major>0|[1-9] \\ d*)
103
+ \\ .
104
+ (?<minor>0|[1-9] \\ d*)
105
+ \\ .
106
+ (?<patch>0|[1-9] \\ d*)
107
+ (?:-
108
+ (?<prerelease>
109
+ (?:0|[1-9] \\ d*| \\ d*[a-zA-Z-][0-9a-zA-Z-]*)
110
+ (?: \\ .
111
+ (?:0|[1-9] \\ d*| \\ d*[a-zA-Z-][0-9a-zA-Z-]*)
112
+ )
113
+ *)
114
+ )?
115
+ (?: \\ +
116
+ (?<buildmetadata>[0-9a-zA-Z-]+
117
+ (?: \\ .[0-9a-zA-Z-]+)
118
+ *)
119
+ )?
120
+ $
121
+ """ , options: [ . allowCommentsAndWhitespace] )
122
+
123
+ #endif
0 commit comments