@@ -57,7 +57,7 @@ public enum VersionError: Error, CustomStringConvertible {
57
57
case nonAlphaNuumerHyphenalPrereleaseIdentifiers( _ identifiers: [ String ] )
58
58
/// Some or all of the build metadata identifiers contain characters other than alpha-numerics and hyphens.
59
59
case nonAlphaNuumerHyphenalBuildMetadataIdentifiers( _ identifiers: [ String ] )
60
-
60
+
61
61
public var description : String {
62
62
switch self {
63
63
case let . nonASCIIVersionString( versionString) :
@@ -99,18 +99,18 @@ extension Version {
99
99
guard versionString. allSatisfy ( \. isASCII) else {
100
100
throw VersionError . nonASCIIVersionString ( versionString)
101
101
}
102
-
102
+
103
103
let metadataDelimiterIndex = versionString. firstIndex ( of: " + " )
104
104
// SemVer 2.0.0 requires that pre-release identifiers come before build metadata identifiers
105
105
let prereleaseDelimiterIndex = versionString [ ..< ( metadataDelimiterIndex ?? versionString. endIndex) ] . firstIndex ( of: " - " )
106
-
106
+
107
107
let versionCore = versionString [ ..< ( prereleaseDelimiterIndex ?? metadataDelimiterIndex ?? versionString. endIndex) ]
108
108
let versionCoreIdentifiers = versionCore. split ( separator: " . " , omittingEmptySubsequences: false )
109
109
110
110
guard versionCoreIdentifiers. count == 3 else {
111
111
throw VersionError . invalidVersionCoreIdentifiersCount ( versionCoreIdentifiers. map { String ( $0) } )
112
112
}
113
-
113
+
114
114
guard
115
115
// Major, minor, and patch versions must be ASCII numbers, according to the semantic versioning standard.
116
116
// Converting each identifier from a substring to an integer doubles as checking if the identifiers have non-numeric characters.
@@ -120,11 +120,11 @@ extension Version {
120
120
else {
121
121
throw VersionError . nonNuumericalOrEmptyVersionCoreIdentifiers ( versionCoreIdentifiers. map { String ( $0) } )
122
122
}
123
-
123
+
124
124
self . major = major
125
125
self . minor = minor
126
126
self . patch = patch
127
-
127
+
128
128
if let prereleaseDelimiterIndex = prereleaseDelimiterIndex {
129
129
let prereleaseStartIndex = versionString. index ( after: prereleaseDelimiterIndex)
130
130
let prereleaseIdentifiers = versionString [ prereleaseStartIndex..< ( metadataDelimiterIndex ?? versionString. endIndex) ] . split ( separator: " . " , omittingEmptySubsequences: false )
@@ -150,17 +150,17 @@ extension Version {
150
150
}
151
151
152
152
extension Version : Comparable , Hashable {
153
-
153
+
154
154
func isEqualWithoutPrerelease( _ other: Version ) -> Bool {
155
155
return major == other. major && minor == other. minor && patch == other. patch
156
156
}
157
-
157
+
158
158
// Although `Comparable` inherits from `Equatable`, it does not provide a new default implementation of `==`, but instead uses `Equatable`'s default synthesised implementation. The compiler-synthesised `==`` is composed of [member-wise comparisons](https://github.com/apple/swift-evolution/blob/main/proposals/0185-synthesize-equatable-hashable.md#implementation-details), which leads to a false `false` when 2 semantic versions differ by only their build metadata identifiers, contradicting SemVer 2.0.0's [comparison rules](https://semver.org/#spec-item-10).
159
159
@inlinable
160
160
public static func == ( lhs: Version , rhs: Version ) -> Bool {
161
161
!( lhs < rhs) && !( lhs > rhs)
162
162
}
163
-
163
+
164
164
public static func < ( lhs: Version , rhs: Version ) -> Bool {
165
165
let lhsComparators = [ lhs. major, lhs. minor, lhs. patch]
166
166
let rhsComparators = [ rhs. major, rhs. minor, rhs. patch]
@@ -174,7 +174,7 @@ extension Version: Comparable, Hashable {
174
174
}
175
175
176
176
guard rhs. prereleaseIdentifiers. count > 0 else {
177
- return true // Prerelease lhs < non-prerelease rhs
177
+ return true // Prerelease lhs < non-prerelease rhs
178
178
}
179
179
180
180
let zippedIdentifiers = zip ( lhs. prereleaseIdentifiers, rhs. prereleaseIdentifiers)
@@ -198,7 +198,7 @@ extension Version: Comparable, Hashable {
198
198
199
199
return lhs. prereleaseIdentifiers. count < rhs. prereleaseIdentifiers. count
200
200
}
201
-
201
+
202
202
// Custom `Equatable` conformance leads to custom `Hashable` conformance.
203
203
// [SR-11588](https://bugs.swift.org/browse/SR-11588)
204
204
public func hash( into hasher: inout Hasher ) {
0 commit comments