mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-19 04:00:54 +00:00
38 lines
1.0 KiB
Swift
38 lines
1.0 KiB
Swift
import Foundation
|
|
|
|
public enum PeerIndexNameRepresentation {
|
|
case title(String)
|
|
case personName(first: String, last: String)
|
|
}
|
|
|
|
public enum PeerNameIndex {
|
|
case firstNameFirst
|
|
case lastNameFirst
|
|
}
|
|
|
|
extension PeerIndexNameRepresentation {
|
|
public func indexName(_ index: PeerNameIndex) -> String {
|
|
switch self {
|
|
case let .title(title):
|
|
return title
|
|
case let .personName(first, last):
|
|
switch index {
|
|
case .firstNameFirst:
|
|
return first + last
|
|
case .lastNameFirst:
|
|
return last + first
|
|
}
|
|
}
|
|
}
|
|
|
|
public func match(query: String) -> Bool {
|
|
switch self {
|
|
case let .title(title):
|
|
return title.lowercased().hasPrefix(query)
|
|
case let .personName(first, last):
|
|
return first.lowercased().hasPrefix(query) || last.lowercased().hasPrefix(query)
|
|
}
|
|
return false
|
|
}
|
|
}
|