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