History

mac/swift: move isUrl check to String extension

der richter committed 1 year ago

Commit c75779d1 parent 6b0e4f72 files · +14 −12Browse files

Unified · Split

2 files
  1. osdep/mac/swift_extensions.swift +13 −0
  2. video/out/mac/view.swift +1 −12
osdep/mac/swift_extensions.swift+13−0
@@ -52,6 +52,19 @@ extension NSEvent.ModifierFlags { · 51 unmodified lines
52 public static let optionRight: NSEvent.ModifierFlags = .init(rawValue: UInt(NX_DEVICERALTKEYMASK))52 public static let optionRight: NSEvent.ModifierFlags = .init(rawValue: UInt(NX_DEVICERALTKEYMASK))
53}53}
54 54
55extension String {
56 func isUrl() -> Bool {
57 guard let regex = try? NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$",
58 options: .caseInsensitive) else {
59 return false
60 }
61 let isUrl = regex.numberOfMatches(in: self,
62 options: [],
63 range: NSRange(location: 0, length: self.count))
64 return isUrl > 0
65 }
66}
67
55extension mp_keymap {68extension mp_keymap {
56 init(_ f: Int, _ t: Int32) {69 init(_ f: Int, _ t: Int32) {
57 self.init(from: Int32(f), to: t)70 self.init(from: Int32(f), to: t)
video/out/mac/view.swift+1−12
@@ -65,17 +65,6 @@ class View: NSView, CALayerDelegate { · 64 unmodified lines
65 return []65 return []
66 }66 }
67 67
68 func isURL(_ str: String) -> Bool {
69 guard let regex = try? NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$",
70 options: .caseInsensitive) else {
71 return false
72 }
73 let isURL = regex.numberOfMatches(in: str,
74 options: [],
75 range: NSRange(location: 0, length: str.count))
76 return isURL > 0
77 }
78
79 override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {68 override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
80 let pb = sender.draggingPasteboard69 let pb = sender.draggingPasteboard
81 guard let types = pb.types else { return false }70 guard let types = pb.types else { return false }
@@ -89,7 +78,7 @@ class View: NSView, CALayerDelegate { · 7 unmodified lines
89 files = str.components(separatedBy: "\n").compactMap {78 files = str.components(separatedBy: "\n").compactMap {
90 let url = $0.trimmingCharacters(in: .whitespacesAndNewlines)79 let url = $0.trimmingCharacters(in: .whitespacesAndNewlines)
91 let path = (url as NSString).expandingTildeInPath80 let path = (url as NSString).expandingTildeInPath
92 if isURL(url) { return url }81 if url.isUrl() { return url }
93 if path.starts(with: "/") { return path }82 if path.starts(with: "/") { return path }
94 return nil83 return nil
95 }84 }

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