     
     fileprivate func encode(record: [String]) -> String {
         let escapedRecord:[String] = record.map { (field) -> String in
-            guard field.contains(quoteCharacter) else {
-                return field
-            }
-            
-            let escapedField = field.replacingOccurrences(of: quoteSequence, with: escapeSequence, options: NSString.CompareOptions.literal, range: nil)
+            let escapedField = field.replacingOccurrences(of: quoteSequence,
+                                                          with: escapeSequence,
+                                                          options: NSString.CompareOptions.literal,
+                                                          range: nil)
             return quoteSequence + escapedField + quoteSequence
         }
-        return escapedRecord.joined(separator: fieldDelimiterSequence)
+        
+        return escapedRecord.joined(separator: fieldDelimiterSequence) + recordDelimiterSequence
     }
 }
 

            // supporting bare CR & LF, not required by RFC4180 but common
			else if !quoted && (current == bareReturn || current == bareLinefeed) {
				testRecordEnd = true
                continue
			}
                
            //if outside of quoted section and at end of record then: add last field to record,

//  Copyright (c) 2014 Frank Vernon. All rights reserved.
//

import Foundation

fileprivate let fieldDelimiter:Character = ","
fileprivate let recordDelimiter:Character = "\r\n"
