Skip to content

Commit

Permalink
Semantic Version 2.1.0 Update (#47)
Browse files Browse the repository at this point in the history
* Semantic Version 2.1.0

* merged Version files

* Remove inlinable to avoid compile errors
  • Loading branch information
kp-cat authored Oct 17, 2024
1 parent 2681439 commit b319ac6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
29 changes: 23 additions & 6 deletions Sources/Version/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
A struct representing a “semver” version, that is: a Semantic Version.
- SeeAlso: https://semver.org
*/

public struct Version {
/// The major version.
public let major: Int
Expand Down Expand Up @@ -48,6 +49,18 @@ public struct Version {
print("notice: negative components were abs’d")
}
}

/**
Creates a version object.
- Note: Integers are made absolute since negative integers are not allowed, yet it is conventional Swift to take `Int` over `UInt` where possible.
- Remark: This initializer variant provided when it would be more readable than the nameless variant.
*/
public init(major: Int, minor: Int, patch: Int, prereleaseIdentifiers: [String] = [], buildMetadataIdentifiers: [String] = []) {
self.init(major, minor, patch, pre: prereleaseIdentifiers, build: buildMetadataIdentifiers)
}

/// Represents `0.0.0`
public static let null = Version(0,0,0)
}

extension Version: LosslessStringConvertible {
Expand Down Expand Up @@ -180,6 +193,10 @@ public extension Version {
}
}

#if swift(>=5.5)
extension Version: Sendable {}
#endif

extension Version: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(major)
Expand All @@ -192,13 +209,13 @@ extension Version: Hashable {
extension Version: Equatable {
/// Compares the provided versions *without* comparing any build-metadata
public static func == (lhs: Version, rhs: Version) -> Bool {
lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch && lhs.prereleaseIdentifiers == rhs.prereleaseIdentifiers
return lhs.major == rhs.major && lhs.minor == rhs.minor && lhs.patch == rhs.patch && lhs.prereleaseIdentifiers == rhs.prereleaseIdentifiers
}
}

extension Version: Comparable {
func isEqualWithoutPrerelease(_ other: Version) -> Bool {
major == other.major && minor == other.minor && patch == other.patch
return major == other.major && minor == other.minor && patch == other.patch
}

/**
Expand Down Expand Up @@ -232,10 +249,10 @@ extension Version: Comparable {
let typedRhsIdentifier: Any = Int(rhsPrereleaseIdentifier) ?? rhsPrereleaseIdentifier

switch (typedLhsIdentifier, typedRhsIdentifier) {
case let (int1 as Int, int2 as Int): return int1 < int2
case let (string1 as String, string2 as String): return string1 < string2
case (is Int, is String): return true // Int prereleases < String prereleases
case (is String, is Int): return false
case let (int1 as Int, int2 as Int): return int1 < int2
case let (string1 as String, string2 as String): return string1 < string2
case (is Int, is String): return true // Int prereleases < String prereleases
case (is String, is Int): return false
default:
fatalError("impossi-op")
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Version/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
https://github.com/mxcl/Version/releases/tag/2.0.1
https://github.com/mxcl/Version/releases/tag/2.1.0
Version+Comparable.swift merged into Version.swift.

0 comments on commit b319ac6

Please sign in to comment.