aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Utility/FoundationExtensions.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-11-27 23:38:04 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2025-11-27 23:38:04 +0100
commit213710bf5bd6413c747bf126db50816ef5de5a6e (patch)
tree912f8cf87955a08077c92fea8ad934f50b7ab975 /Hotline/Utility/FoundationExtensions.swift
parentf466b21dc02f78c984ba6748e703f6780a7a0db4 (diff)
parent6a95b53616a4abfa306ddce43151cf4fefbd20ed (diff)
Merge remote-tracking branch 'upstream/main'
Diffstat (limited to 'Hotline/Utility/FoundationExtensions.swift')
-rw-r--r--Hotline/Utility/FoundationExtensions.swift87
1 files changed, 0 insertions, 87 deletions
diff --git a/Hotline/Utility/FoundationExtensions.swift b/Hotline/Utility/FoundationExtensions.swift
deleted file mode 100644
index b1cd1b9..0000000
--- a/Hotline/Utility/FoundationExtensions.swift
+++ /dev/null
@@ -1,87 +0,0 @@
-import Foundation
-import SwiftUI
-
-enum Endianness {
- case big
- case little
-}
-
-extension String {
-
- func convertToAttributedStringWithLinks() -> AttributedString {
- let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: self)
- let matches = self.ranges(of: RegularExpressions.relaxedLink)
- for match in matches {
- let matchString = String(self[match])
- if matchString.isEmailAddress() {
- attributedString.addAttribute(
- .link, value: "mailto:\(matchString)", range: NSRange(match, in: self))
- } else {
- attributedString.addAttribute(.link, value: matchString, range: NSRange(match, in: self))
- }
- // attributedString.addAttribute(.underlineStyle, value: 1, range: NSRange(match, in: self))
- }
- return AttributedString(attributedString)
- }
-
- func isEmailAddress() -> Bool {
- self.wholeMatch(of: RegularExpressions.emailAddress) != nil
- }
-
- func isWebURL() -> Bool {
- guard let url = URL(string: self) else {
- return false
- }
- switch url.scheme?.lowercased() {
- case "http", "https":
- return true
- default:
- return false
- }
- }
-
- func isImageURL() -> Bool {
- guard let url = URL(string: self) else {
- return false
- }
-
- switch url.pathExtension.lowercased() {
- case "jpg", "jpeg", "png", "gif":
- return true
- default:
- return false
- }
- }
-
- func convertingLinksToMarkdown() -> String {
- var cp = String(self)
- cp.replace(RegularExpressions.relaxedLink) { match -> String in
- let linkText = self[match.range]
- var injectedScheme = "https://"
- if (try? RegularExpressions.supportedLinkScheme.prefixMatch(in: linkText)) != nil {
- injectedScheme = ""
- }
-
- return "[\(linkText)](\(injectedScheme)\(linkText))"
- }
- return cp
- }
-}
-
-extension Binding where Value: OptionSet, Value == Value.Element {
- func bindedValue(_ options: Value) -> Bool {
- return wrappedValue.contains(options)
- }
-
- func bind(_ options: Value) -> Binding<Bool> {
- return .init { () -> Bool in
- self.wrappedValue.contains(options)
- } set: { newValue in
- if newValue {
- self.wrappedValue.insert(options)
- } else {
- self.wrappedValue.remove(options)
- }
- }
- }
-}