mirror of https://github.com/mpv-player/mpv
mac: properly handle regular expressions without force unwrap
This commit is contained in:
parent
8f1189341f
commit
4a686dac6f
|
@ -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),
|
||||
|
|
|
@ -64,9 +64,10 @@ class View: NSView, CALayerDelegate {
|
|||
}
|
||||
|
||||
func isURL(_ str: String) -> Bool {
|
||||
// force unwrapping is fine here, regex is guaranteed to be valid
|
||||
let regex = try! NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$",
|
||||
options: .caseInsensitive)
|
||||
guard let regex = try? NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$",
|
||||
options: .caseInsensitive) else {
|
||||
return false
|
||||
}
|
||||
let isURL = regex.numberOfMatches(in: str,
|
||||
options: [],
|
||||
range: NSRange(location: 0, length: str.count))
|
||||
|
|
Loading…
Reference in New Issue