Trim even if one-line-string does not end with \n.

I do think a string with only one newline, placed at the end, still has just one line.
This commit is contained in:
Kare Morstol
2015-08-09 22:37:47 +02:00
parent a23f680cbf
commit 2cd0b9bf4d
+4 -2
View File
@@ -45,8 +45,10 @@ extension ShellContextType {
var outputstring = output.fileHandleForReading.read(encoding: self.encoding)
// if output is single-line, trim it.
if outputstring.hasSuffix("\n") && outputstring.characters.indexOf("\n") == outputstring.endIndex.predecessor() {
outputstring = outputstring.stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet())
let firstnewline = outputstring.characters.indexOf("\n")
if firstnewline == nil ||
firstnewline == outputstring.endIndex.predecessor() {
outputstring = outputstring.stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet())
}
return outputstring