From 238c5e4809c0b9139f42af6a8308cf3cb250ae28 Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Sun, 3 Jul 2016 15:58:57 +0900 Subject: [PATCH 1/6] Quote space-containing arguments in Task.description --- ReactiveTask/Task.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index d2fa1fb..800d243 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -48,6 +48,13 @@ public struct Task { extension Task: CustomStringConvertible { public var description: String { + let arguments = self.arguments.map { argument -> String in + if argument.containsString(" ") { + return "\"\(argument)\"" + } else { + return argument + } + } return "\(launchPath) \(arguments.joinWithSeparator(" "))" } } From 58a006034235ca2ab4db647c8b9d99181d920c46 Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Tue, 5 Jul 2016 13:47:51 +0900 Subject: [PATCH 2/6] Use NSCharacterSet to detect a whitespace character --- ReactiveTask/Task.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 800d243..589cb5a 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -48,8 +48,9 @@ public struct Task { extension Task: CustomStringConvertible { public var description: String { + let whitespaceCharacterSet = NSCharacterSet.whitespaceCharacterSet() let arguments = self.arguments.map { argument -> String in - if argument.containsString(" ") { + if argument.rangeOfCharacterFromSet(whitespaceCharacterSet) != nil { return "\"\(argument)\"" } else { return argument From 3ead6f5f1d67f202596353cb1b5d56719b384e45 Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Tue, 5 Jul 2016 13:53:23 +0900 Subject: [PATCH 3/6] Add an extension method to CollectionType --- ReactiveTask/Task.swift | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 589cb5a..3d4a799 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -46,17 +46,22 @@ public struct Task { } } -extension Task: CustomStringConvertible { - public var description: String { +private extension CollectionType where Generator.Element == String { + func escaped() -> [String] { let whitespaceCharacterSet = NSCharacterSet.whitespaceCharacterSet() - let arguments = self.arguments.map { argument -> String in - if argument.rangeOfCharacterFromSet(whitespaceCharacterSet) != nil { - return "\"\(argument)\"" + return map { string -> String in + if string.rangeOfCharacterFromSet(whitespaceCharacterSet) != nil { + return "\"\(string)\"" } else { - return argument + return string } } - return "\(launchPath) \(arguments.joinWithSeparator(" "))" + } +} + +extension Task: CustomStringConvertible { + public var description: String { + return "\(launchPath) \(arguments.escaped().joinWithSeparator(" "))" } } From b98b160a543b0f189b117f77f0f5415ee6367a6f Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Tue, 5 Jul 2016 14:37:28 +0900 Subject: [PATCH 4/6] Revert "Add an extension method to CollectionType" This reverts commit 3ead6f5f1d67f202596353cb1b5d56719b384e45. --- ReactiveTask/Task.swift | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 3d4a799..589cb5a 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -46,22 +46,17 @@ public struct Task { } } -private extension CollectionType where Generator.Element == String { - func escaped() -> [String] { +extension Task: CustomStringConvertible { + public var description: String { let whitespaceCharacterSet = NSCharacterSet.whitespaceCharacterSet() - return map { string -> String in - if string.rangeOfCharacterFromSet(whitespaceCharacterSet) != nil { - return "\"\(string)\"" + let arguments = self.arguments.map { argument -> String in + if argument.rangeOfCharacterFromSet(whitespaceCharacterSet) != nil { + return "\"\(argument)\"" } else { - return string + return argument } } - } -} - -extension Task: CustomStringConvertible { - public var description: String { - return "\(launchPath) \(arguments.escaped().joinWithSeparator(" "))" + return "\(launchPath) \(arguments.joinWithSeparator(" "))" } } From 9170a0a0cdf6ce762dae373bf8e7ce871b892042 Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Tue, 5 Jul 2016 14:40:58 +0900 Subject: [PATCH 5/6] `extension String` --- ReactiveTask/Task.swift | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 589cb5a..2f5841d 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -46,17 +46,20 @@ public struct Task { } } -extension Task: CustomStringConvertible { - public var description: String { +private extension String { + var escaped: String { let whitespaceCharacterSet = NSCharacterSet.whitespaceCharacterSet() - let arguments = self.arguments.map { argument -> String in - if argument.rangeOfCharacterFromSet(whitespaceCharacterSet) != nil { - return "\"\(argument)\"" - } else { - return argument - } + if rangeOfCharacterFromSet(whitespaceCharacterSet) != nil { + return "\"\(self)\"" + } else { + return self } - return "\(launchPath) \(arguments.joinWithSeparator(" "))" + } +} + +extension Task: CustomStringConvertible { + public var description: String { + return "\(launchPath) \(arguments.map { $0.escaped }.joinWithSeparator(" "))" } } From 9e4b12e8398c7ffca1eec897ebc0aab997d5a7a1 Mon Sep 17 00:00:00 2001 From: Syo Ikeda Date: Tue, 5 Jul 2016 14:43:11 +0900 Subject: [PATCH 6/6] Simplify --- ReactiveTask/Task.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 2f5841d..aac9409 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -48,8 +48,7 @@ public struct Task { private extension String { var escaped: String { - let whitespaceCharacterSet = NSCharacterSet.whitespaceCharacterSet() - if rangeOfCharacterFromSet(whitespaceCharacterSet) != nil { + if rangeOfCharacterFromSet(.whitespaceCharacterSet()) != nil { return "\"\(self)\"" } else { return self