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 {
|
public var name: String {
|
||||||
// force unwrapping is fine here, regex is guaranteed to be valid
|
guard let regex = try? NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive) else {
|
||||||
let regex = try! NSRegularExpression(pattern: " \\(\\d+\\)$", options: .caseInsensitive)
|
return localizedName
|
||||||
|
}
|
||||||
return regex.stringByReplacingMatches(
|
return regex.stringByReplacingMatches(
|
||||||
in: localizedName,
|
in: localizedName,
|
||||||
range: NSRange(location: 0, length: localizedName.count),
|
range: NSRange(location: 0, length: localizedName.count),
|
||||||
|
|
|
@ -64,9 +64,10 @@ class View: NSView, CALayerDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isURL(_ str: String) -> Bool {
|
func isURL(_ str: String) -> Bool {
|
||||||
// force unwrapping is fine here, regex is guaranteed to be valid
|
guard let regex = try? NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$",
|
||||||
let regex = try! NSRegularExpression(pattern: "^(https?|ftp)://[^\\s/$.?#].[^\\s]*$",
|
options: .caseInsensitive) else {
|
||||||
options: .caseInsensitive)
|
return false
|
||||||
|
}
|
||||||
let isURL = regex.numberOfMatches(in: str,
|
let isURL = regex.numberOfMatches(in: str,
|
||||||
options: [],
|
options: [],
|
||||||
range: NSRange(location: 0, length: str.count))
|
range: NSRange(location: 0, length: str.count))
|
||||||
|
|
Loading…
Reference in New Issue