Sha256: 1037ac52b5064b9d30674dce4fc861dea0629475f1c8b47fe6d001dec7994e1c
Contents?: true
Size: 1.14 KB
Versions: 137
Compression:
Stored size: 1.14 KB
Contents
import Foundation private extension String { subscript (range: CountableClosedRange<Int>) -> String { get { let start = characters.index(startIndex, offsetBy: range.lowerBound) let end = characters.index(start, offsetBy: range.upperBound - range.lowerBound) return self[start...end] } } var onlyDigits: String { return String(characters.filter { $0.isDigit }) } } private extension Character { var isDigit: Bool { return "0123456789".characters.contains(self) } } struct PhoneNumber: CustomStringConvertible { let number: String init(_ startingNumber: String) { let digits = startingNumber.onlyDigits switch digits.characters.count { case 10: number = digits case 11 where digits.hasPrefix("1"): number = digits[1...10] default: number = "0000000000" } } var areaCode: String { return number[0...2] } var description: String { let prefix = number[3...5] let final = number[6...9] return "(\(areaCode)) \(prefix)-\(final)" } }
Version data entries
137 entries across 137 versions & 1 rubygems