From be6abdcf2af3e4f23c9876f1f8a07539b59d8fbc Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 21 Oct 2018 09:35:46 +0200 Subject: [PATCH] Move file-to-lines to String extension --- Passepartout/Sources/Utils.swift | 10 ++++++++++ .../VPN/TunnelKitProvider+FileConfiguration.swift | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Passepartout/Sources/Utils.swift b/Passepartout/Sources/Utils.swift index f4a46423..0c178870 100644 --- a/Passepartout/Sources/Utils.swift +++ b/Passepartout/Sources/Utils.swift @@ -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 + } + } +} diff --git a/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift b/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift index dcd4a56a..66a0152d 100644 --- a/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift +++ b/Passepartout/Sources/VPN/TunnelKitProvider+FileConfiguration.swift @@ -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?