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 {
|
private struct ParsedFile {
|
||||||
let url: URL
|
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 hostname: String
|
||||||
|
|
||||||
let configuration: TunnelKitProvider.Configuration
|
let configuration: TunnelKitProvider.Configuration
|
||||||
|
@ -118,7 +113,7 @@ class WizardHostViewController: UITableViewController, TableModelHost, Wizard {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if field.text?.isEmpty ?? true {
|
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)
|
let cell = Cells.field.dequeue(from: tableView, for: indexPath)
|
||||||
cell.caption = L10n.Wizards.Host.Cells.TitleInput.caption
|
cell.caption = L10n.Wizards.Host.Cells.TitleInput.caption
|
||||||
cell.captionWidth = 100.0
|
cell.captionWidth = 100.0
|
||||||
cell.allowedCharset = AppConstants.Store.filenameCharset
|
cell.allowedCharset = .filename
|
||||||
cell.field.placeholder = L10n.Wizards.Host.Cells.TitleInput.placeholder
|
cell.field.placeholder = L10n.Wizards.Host.Cells.TitleInput.placeholder
|
||||||
cell.field.clearButtonMode = .always
|
cell.field.clearButtonMode = .always
|
||||||
cell.field.returnKeyType = .done
|
cell.field.returnKeyType = .done
|
||||||
|
|
|
@ -40,16 +40,6 @@ class AppConstants {
|
||||||
static let providersDirectory = "Providers"
|
static let providersDirectory = "Providers"
|
||||||
|
|
||||||
static let hostsDirectory = "Hosts"
|
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 {
|
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