Move filename charset to extensions
This commit is contained in:
parent
4bcb1fe2ad
commit
0d14349bca
|
@ -33,11 +33,6 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
|||
private struct ParsedFile {
|
||||
let url: URL
|
||||
|
||||
var filename: String {
|
||||
let raw = url.deletingPathExtension().lastPathComponent
|
||||
return raw.components(separatedBy: AppConstants.Store.filenameCharset.inverted).joined(separator: "_")
|
||||
}
|
||||
|
||||
let hostname: String
|
||||
|
||||
let configuration: TunnelKitProvider.Configuration
|
||||
|
@ -118,7 +113,7 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
|||
return
|
||||
}
|
||||
if field.text?.isEmpty ?? true {
|
||||
field.text = parsedFile?.filename
|
||||
field.text = parsedFile?.url.normalizedFilename
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,7 +211,7 @@ extension WizardHostViewController {
|
|||
let cell = Cells.field.dequeue(from: tableView, for: indexPath)
|
||||
cell.caption = L10n.Wizards.Host.Cells.TitleInput.caption
|
||||
cell.captionWidth = 100.0
|
||||
cell.allowedCharset = AppConstants.Store.filenameCharset
|
||||
cell.allowedCharset = .filename
|
||||
cell.field.placeholder = L10n.Wizards.Host.Cells.TitleInput.placeholder
|
||||
cell.field.clearButtonMode = .always
|
||||
cell.field.returnKeyType = .done
|
||||
|
|
|
@ -40,16 +40,6 @@ class AppConstants {
|
|||
static let providersDirectory = "Providers"
|
||||
|
||||
static let hostsDirectory = "Hosts"
|
||||
|
||||
static let filenameCharset: CharacterSet = {
|
||||
var chars: CharacterSet = .decimalDigits
|
||||
let english = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
let symbols = "-_"
|
||||
chars.formUnion(CharacterSet(charactersIn: english))
|
||||
chars.formUnion(CharacterSet(charactersIn: english.lowercased()))
|
||||
chars.formUnion(CharacterSet(charactersIn: symbols))
|
||||
return chars
|
||||
}()
|
||||
}
|
||||
|
||||
class VPN {
|
||||
|
|
|
@ -201,3 +201,24 @@ extension String {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension CharacterSet {
|
||||
static let filename: CharacterSet = {
|
||||
var chars: CharacterSet = .decimalDigits
|
||||
let english = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
let symbols = "-_"
|
||||
chars.formUnion(CharacterSet(charactersIn: english))
|
||||
chars.formUnion(CharacterSet(charactersIn: english.lowercased()))
|
||||
chars.formUnion(CharacterSet(charactersIn: symbols))
|
||||
return chars
|
||||
}()
|
||||
}
|
||||
|
||||
extension URL {
|
||||
private static let illegalCharacterFallback = "_"
|
||||
|
||||
var normalizedFilename: String {
|
||||
let filename = deletingPathExtension().lastPathComponent
|
||||
return filename.components(separatedBy: CharacterSet.filename.inverted).joined(separator: URL.illegalCharacterFallback)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue