-
Notifications
You must be signed in to change notification settings - Fork 400
Expand file tree
/
Copy pathCaseInsensitiveStringSet+Conformances.swift
More file actions
62 lines (55 loc) · 2 KB
/
Copy pathCaseInsensitiveStringSet+Conformances.swift
File metadata and controls
62 lines (55 loc) · 2 KB
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
56
57
58
59
60
61
62
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
import Foundation
extension CaseInsensitiveStringSet: CustomDebugStringConvertible {
public var debugDescription: String {
String(describing: Self.self)
+ "([\(self.lazy.map(String.init(reflecting:)).joined(separator: ", "))])"
}
}
extension CaseInsensitiveStringSet: CustomReflectable {
public var customMirror: Mirror {
Mirror(self, unlabeledChildren: Array(self), displayStyle: .set)
}
}
extension CaseInsensitiveStringSet: CustomStringConvertible {
public var description: String {
"[\(self.lazy.map({ $0.folding(options: .caseInsensitive, locale: nil) }).map(String.init(reflecting:)).joined(separator: ", "))]"
}
}
extension CaseInsensitiveStringSet: Decodable {
public init(from decoder: any Decoder) throws {
var container = try decoder.unkeyedContainer()
var strings = [String]()
strings.reserveCapacity(container.count ?? 0)
while !container.isAtEnd {
strings.append(try container.decode(String.self))
}
self.init(strings)
}
}
extension CaseInsensitiveStringSet: Encodable {
public func encode(to encoder: any Encoder) throws {
var container = encoder.unkeyedContainer()
try container.encode(contentsOf: self)
}
}
extension CaseInsensitiveStringSet: Hashable {
public func hash(into hasher: inout Hasher) {
for element in self {
var folded = element.folding(options: .caseInsensitive, locale: nil)
folded = folded.decomposedStringWithCanonicalMapping
folded.withUTF8 { hasher.combine(bytes: UnsafeRawBufferPointer($0)) }
}
}
}