Move file-to-lines to String extension

This commit is contained in:
Davide De Rosa 2018-10-21 09:35:46 +02:00
parent a20512e295
commit be6abdcf2a
2 changed files with 11 additions and 2 deletions

View File

@ -191,3 +191,13 @@ extension StringProtocol where Index == String.Index {
return NSRange(range, in: self)
}
}
extension String {
func trimmedLines() -> [String] {
return components(separatedBy: .newlines).map {
$0.trimmingCharacters(in: .whitespacesAndNewlines)
}.filter {
!$0.isEmpty
}
}
}

View File

@ -59,8 +59,7 @@ extension TunnelKitProvider.Configuration {
}
static func parsed(from url: URL) throws -> (String, TunnelKitProvider.Configuration) {
let content = try String(contentsOf: url)
let lines = content.components(separatedBy: .newlines).map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.filter { !$0.isEmpty }
let lines = try String(contentsOf: url).trimmedLines()
var defaultProto: TunnelKitProvider.SocketType?
var defaultPort: UInt16?