summaryrefslogtreecommitdiffstats
path: root/osdep/mac
diff options
context:
space:
mode:
authorder richter <der.richter@gmx.de>2024-04-27 22:36:02 +0200
committerder richter <der.richter@gmx.de>2024-04-28 20:21:18 +0200
commit4a686dac6f2df3b1e8f0a315c41a0a79a853741b (patch)
tree85ed169aac2e70d644c6f383d60a1882964f5327 /osdep/mac
parent8f1189341fcc5cddc92056078aa2439d451d1c98 (diff)
downloadmpv-4a686dac6f2df3b1e8f0a315c41a0a79a853741b.tar.bz2
mpv-4a686dac6f2df3b1e8f0a315c41a0a79a853741b.tar.xz
mac: properly handle regular expressions without force unwrap
Diffstat (limited to 'osdep/mac')
-rw-r--r--osdep/mac/swift_extensions.swift5
1 files changed, 3 insertions, 2 deletions
diff --git a/osdep/mac/swift_extensions.swift b/osdep/mac/swift_extensions.swift
index 2399c86509..e49806aaa0 100644
--- a/osdep/mac/swift_extensions.swift
+++ b/osdep/mac/swift_extensions.swift
@@ -32,8 +32,9 @@ extension NSScreen {
}
public var name: String {
- // force unwrapping is fine here, regex is guaranteed to be valid
- let regex = try! NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive)
+ guard let regex = try? NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive) else {
+ return localizedName
+ }
return regex.stringByReplacingMatches(
in: localizedName,
range: NSRange(location: 0, length: localizedName.count),