28 lines · 1.0 KB · Swift
RawDownload
import Foundation enum PersonalInfoRedactor {    static let emailPlaceholder = "Hidden"     private static let emailRegex: NSRegularExpression? = {        let pattern = #"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}"#        return try? NSRegularExpression(pattern: pattern, options: [.caseInsensitive])    }()     static func redactEmail(_ email: String?, isEnabled: Bool) -> String {        guard let email, !email.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return "" }        guard isEnabled else { return email }        return Self.emailPlaceholder    }     static func redactEmails(in text: String?, isEnabled: Bool) -> String? {        guard let text else { return nil }        guard isEnabled else { return text }        guard let regex = Self.emailRegex else { return text }        let range = NSRange(text.startIndex..<text.endIndex, in: text)        return regex.stringByReplacingMatches(            in: text,            options: [],            range: range,            withTemplate: Self.emailPlaceholder)    }}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t