Skip to content

Commit 777a15a

Browse files
authored
Update PackageIdentity to be case-insensitive (#3749)
* Refine PackageIdentity Equatable conformance to be case-insensitive * Use Foundation string methods for case-insensitive comparisons
1 parent ea746c3 commit 777a15a

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Sources/PackageModel/PackageIdentity.swift

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal protocol PackageIdentityProvider: CustomStringConvertible {
2727
}
2828

2929
/// The canonical identifier for a package, based on its source location.
30-
public struct PackageIdentity: Hashable, CustomStringConvertible {
30+
public struct PackageIdentity: CustomStringConvertible {
3131
/// The underlying type used to create package identities.
3232
internal static var provider: PackageIdentityProvider.Type = LegacyPackageIdentity.self
3333

@@ -59,9 +59,27 @@ public struct PackageIdentity: Hashable, CustomStringConvertible {
5959
}
6060
}
6161

62-
extension PackageIdentity: Comparable {
62+
extension PackageIdentity: Equatable, Comparable {
63+
private func compare(to other: PackageIdentity) -> ComparisonResult {
64+
return self.description.caseInsensitiveCompare(other.description)
65+
}
66+
67+
public static func == (lhs: PackageIdentity, rhs: PackageIdentity) -> Bool {
68+
return lhs.compare(to: rhs) == .orderedSame
69+
}
70+
6371
public static func < (lhs: PackageIdentity, rhs: PackageIdentity) -> Bool {
64-
return lhs.description < rhs.description
72+
return lhs.compare(to: rhs) == .orderedAscending
73+
}
74+
75+
public static func > (lhs: PackageIdentity, rhs: PackageIdentity) -> Bool {
76+
return lhs.compare(to: rhs) == .orderedDescending
77+
}
78+
}
79+
80+
extension PackageIdentity: Hashable {
81+
public func hash(into hasher: inout Hasher) {
82+
hasher.combine(description.lowercased())
6583
}
6684
}
6785

0 commit comments

Comments
 (0)