Merge pull request #1171 from spevans/pr_characters_deprecate

diff --git a/Foundation/HTTPCookie.swift b/Foundation/HTTPCookie.swift
index 2fc9fbc..fcd284c 100644
--- a/Foundation/HTTPCookie.swift
+++ b/Foundation/HTTPCookie.swift
@@ -249,7 +249,7 @@
         _domain = canonicalDomain
 
         if let
-            secureString = properties[.secure] as? String, !secureString.characters.isEmpty
+            secureString = properties[.secure] as? String, !secureString.isEmpty
         {
             _secure = true
         } else {
@@ -267,8 +267,7 @@
         _version = version
 
         if let portString = properties[.port] as? String, _version == 1 {
-            _portList = portString.characters
-                .split(separator: ",")
+            _portList = portString.split(separator: ",")
                 .flatMap { Int(String($0)) }
                 .map { NSNumber(value: $0) }
         } else {
@@ -361,8 +360,8 @@
         }
         //Remove the final trailing semicolon and whitespace
         if ( cookieString.length > 0 ) {
-            cookieString.characters.removeLast()
-            cookieString.characters.removeLast()
+            cookieString.removeLast()
+            cookieString.removeLast()
         }
         return ["Cookie": cookieString]
     }
@@ -624,7 +623,7 @@
     }
 
     func insertComma(at index:Int) -> String {
-        return  String(self.characters.prefix(index)) + ","  + String(self.characters.suffix(self.characters.count-index))
+        return  String(self.prefix(index)) + ","  + String(self.suffix(self.count-index))
     }
 }
 
diff --git a/Foundation/JSONSerialization.swift b/Foundation/JSONSerialization.swift
index 52adb80..d4a1201 100644
--- a/Foundation/JSONSerialization.swift
+++ b/Foundation/JSONSerialization.swift
@@ -286,8 +286,8 @@
 //MARK: - JSONSerializer
 private struct JSONWriter {
     
-    private let maxUIntLength = String(describing: UInt.max).characters.count
-    private let maxIntLength = String(describing: Int.max).characters.count
+    private let maxUIntLength = String(describing: UInt.max).count
+    private let maxIntLength = String(describing: Int.max).count
     var indent = 0
     let pretty: Bool
     let sortedKeys: Bool
diff --git a/Foundation/NSPathUtilities.swift b/Foundation/NSPathUtilities.swift
index 4590787..0126716 100644
--- a/Foundation/NSPathUtilities.swift
+++ b/Foundation/NSPathUtilities.swift
@@ -35,18 +35,16 @@
 
 internal extension String {
     
-    internal var _startOfLastPathComponent : String.CharacterView.Index {
+    internal var _startOfLastPathComponent : String.Index {
         precondition(!hasSuffix("/") && length > 1)
         
-        let characterView = characters
-        let startPos = characterView.startIndex
-        let endPos = characterView.endIndex
-        var curPos = endPos
+        let startPos = startIndex
+        var curPos = endIndex
         
         // Find the beginning of the component
         while curPos > startPos {
-            let prevPos = characterView.index(before: curPos)
-            if characterView[prevPos] == "/" {
+            let prevPos = index(before: curPos)
+            if self[prevPos] == "/" {
                 break
             }
             curPos = prevPos
@@ -55,19 +53,16 @@
 
     }
 
-    internal var _startOfPathExtension : String.CharacterView.Index? {
+    internal var _startOfPathExtension : String.Index? {
         precondition(!hasSuffix("/"))
         
-        let characterView = self.characters
-        let endPos = characterView.endIndex
-        var curPos = endPos
-        
+        var curPos = endIndex
         let lastCompStartPos = _startOfLastPathComponent
         
         // Find the beginning of the extension
         while curPos > lastCompStartPos {
-            let prevPos = characterView.index(before: curPos)
-            let char = characterView[prevPos]
+            let prevPos = index(before: curPos)
+            let char = self[prevPos]
             if char == "/" {
                 return nil
             } else if char == "." {
@@ -125,7 +120,7 @@
             }
         }
         if stripTrailing && result.length > 1 && result.hasSuffix("/") {
-            result.remove(at: result.characters.index(before: result.characters.endIndex))
+            result.remove(at: result.index(before: result.endIndex))
         }
         return result
     }
@@ -181,7 +176,7 @@
             return fixedSelf
         }
         
-        return String(fixedSelf.characters.suffix(from: fixedSelf._startOfLastPathComponent))
+        return String(fixedSelf.suffix(from: fixedSelf._startOfLastPathComponent))
     }
     
     public var deletingLastPathComponent : String {
@@ -202,7 +197,7 @@
         
         // all common cases
         case let startOfLast:
-            return String(fixedSelf.characters.prefix(upTo: fixedSelf.index(before: startOfLast)))
+            return String(fixedSelf.prefix(upTo: fixedSelf.index(before: startOfLast)))
         }
     }
     
@@ -236,7 +231,7 @@
             }
         }
         if stripTrailing && result.hasSuffix("/") {
-            result.remove(at: result.characters.index(before: result.characters.endIndex))
+            result.remove(at: result.index(before: result.endIndex))
         }
         return result
     }
@@ -265,7 +260,7 @@
         }
 
         if let extensionPos = fixedSelf._startOfPathExtension {
-            return String(fixedSelf.characters.suffix(from: extensionPos))
+            return String(fixedSelf.suffix(from: extensionPos))
         } else {
             return ""
         }
@@ -277,7 +272,7 @@
             return fixedSelf
         }
         if let extensionPos = (fixedSelf._startOfPathExtension) {
-            return String(fixedSelf.characters.prefix(upTo: fixedSelf.characters.index(before: extensionPos)))
+            return String(fixedSelf.prefix(upTo: fixedSelf.index(before: extensionPos)))
         } else {
             return fixedSelf
         }
@@ -297,9 +292,9 @@
             return _swiftObject
         }
 
-        let endOfUserName = _swiftObject.characters.index(of: "/") ?? _swiftObject.endIndex
-        let startOfUserName = _swiftObject.characters.index(after: _swiftObject.characters.startIndex)
-        let userName = String(_swiftObject.characters[startOfUserName..<endOfUserName])
+        let endOfUserName = _swiftObject.index(of: "/") ?? _swiftObject.endIndex
+        let startOfUserName = _swiftObject.index(after: _swiftObject.startIndex)
+        let userName = String(_swiftObject[startOfUserName..<endOfUserName])
         let optUserName: String? = userName.isEmpty ? nil : userName
         
         guard let homeDir = NSHomeDirectoryForUser(optUserName) else {
@@ -478,7 +473,7 @@
             return strings.first
         }
         
-        var sequences = strings.map({ $0.characters.makeIterator() })
+        var sequences = strings.map({ $0.makeIterator() })
         var prefix: [Character] = []
         loop: while true {
             var char: Character? = nil
@@ -490,8 +485,8 @@
                 }
                 
                 if char != nil {
-                    let lhs = caseSensitive ? char : String(char!).lowercased().characters.first!
-                    let rhs = caseSensitive ? c : String(c).lowercased().characters.first!
+                    let lhs = caseSensitive ? char : String(char!).lowercased().first!
+                    let rhs = caseSensitive ? c : String(c).lowercased().first!
                     if lhs != rhs {
                         break loop
                     }
diff --git a/Foundation/NSStringAPI.swift b/Foundation/NSStringAPI.swift
index 49d374a..a5e1b00 100644
--- a/Foundation/NSStringAPI.swift
+++ b/Foundation/NSStringAPI.swift
@@ -292,7 +292,7 @@
       aString,
       options: mask,
       range: _toNSRange(
-        range ?? self.characters.startIndex..<self.characters.endIndex
+        range ?? self.startIndex..<self.endIndex
       ),
       locale: locale?._bridgeToObjectiveC()
     )
@@ -1060,7 +1060,7 @@
         from: aSet,
         options: mask,
         range: _toNSRange(
-          aRange ?? self.characters.startIndex..<self.characters.endIndex
+          aRange ?? self.startIndex..<self.endIndex
         )
       )
     )
@@ -1120,7 +1120,7 @@
         of: aString,
         options: mask,
         range: _toNSRange(
-          searchRange ?? self.characters.startIndex..<self.characters.endIndex
+          searchRange ?? self.startIndex..<self.endIndex
         ),
         locale: locale
       )
@@ -1343,7 +1343,7 @@
       with: replacement,
       options: options,
       range: _toNSRange(
-        searchRange ?? self.characters.startIndex..<self.characters.endIndex
+        searchRange ?? self.startIndex..<self.endIndex
       )
     )
     : _ns.replacingOccurrences(of: target, with: replacement)
diff --git a/Foundation/NSURL.swift b/Foundation/NSURL.swift
index 06a5217..697c488 100644
--- a/Foundation/NSURL.swift
+++ b/Foundation/NSURL.swift
@@ -34,7 +34,7 @@
         if p.length == 0 {
             return result
         } else {
-            let characterView = p.characters
+            let characterView = p
             var curPos = characterView.startIndex
             let endPos = characterView.endIndex
             if characterView[curPos] == "/" {
@@ -738,7 +738,7 @@
                 }
             }
             if stripTrailing && result.hasSuffix("/") {
-                result.remove(at: result.characters.index(before: result.characters.endIndex))
+                result.remove(at: result.index(before: result.endIndex))
             }
             return result
         }
@@ -757,7 +757,7 @@
             return fixedSelf
         }
         
-        return String(fixedSelf.characters.suffix(from: fixedSelf._startOfLastPathComponent))
+        return String(fixedSelf.suffix(from: fixedSelf._startOfLastPathComponent))
     }
     
     open var pathExtension: String? {
@@ -769,7 +769,7 @@
         }
         
         if let extensionPos = fixedSelf._startOfPathExtension {
-            return String(fixedSelf.characters.suffix(from: extensionPos))
+            return String(fixedSelf.suffix(from: extensionPos))
         } else {
             return ""
         }
diff --git a/Foundation/ProcessInfo.swift b/Foundation/ProcessInfo.swift
index 10c32fe..baa9dab 100644
--- a/Foundation/ProcessInfo.swift
+++ b/Foundation/ProcessInfo.swift
@@ -92,7 +92,7 @@
             return OperatingSystemVersion(majorVersion: fallbackMajor, minorVersion: fallbackMinor, patchVersion: fallbackPatch)
         }
         
-        let versionComponents = productVersion._swiftObject.characters.split(separator: ".").map(String.init).flatMap({ Int($0) })
+        let versionComponents = productVersion._swiftObject.split(separator: ".").map(String.init).flatMap({ Int($0) })
         let majorVersion = versionComponents.dropFirst(0).first ?? fallbackMajor
         let minorVersion = versionComponents.dropFirst(1).first ?? fallbackMinor
         let patchVersion = versionComponents.dropFirst(2).first ?? fallbackPatch
diff --git a/Foundation/XMLNode.swift b/Foundation/XMLNode.swift
index b1095d0..18c8719 100644
--- a/Foundation/XMLNode.swift
+++ b/Foundation/XMLNode.swift
@@ -421,7 +421,7 @@
         var entityChars: [Character] = []
         var inEntity = false
         var startIndex = 0
-        for (index, char) in string.characters.enumerated() {
+        for (index, char) in string.enumerated() {
             if char == "&" {
                 inEntity = true
                 startIndex = index
@@ -440,7 +440,7 @@
             }
         }
 
-        var result: [Character] = Array(string.characters)
+        var result: [Character] = Array(string)
         let doc = _CFXMLNodeGetDocument(_xmlNode)!
         for (range, entity) in entities {
             var entityPtr = _CFXMLGetDocEntity(doc, entity)
@@ -452,7 +452,7 @@
             }
             if let validEntity = entityPtr {
                 let replacement = _CFXMLCopyEntityContent(validEntity)?._swiftObject ?? ""
-                result.replaceSubrange(range, with: replacement.characters)
+                result.replaceSubrange(range, with: replacement)
             } else {
                 result.replaceSubrange(range, with: []) // This appears to be how Darwin Foundation does it
             }
diff --git a/TestFoundation/HTTPServer.swift b/TestFoundation/HTTPServer.swift
index b129f74..39c8b9c 100644
--- a/TestFoundation/HTTPServer.swift
+++ b/TestFoundation/HTTPServer.swift
@@ -100,7 +100,7 @@
     }
     
     func split(_ str: String, _ count: Int) -> [String] {
-        return stride(from: 0, to: str.characters.count, by: count).map { i -> String in
+        return stride(from: 0, to: str.count, by: count).map { i -> String in
             let startIndex = str.index(str.startIndex, offsetBy: i)
             let endIndex   = str.index(startIndex, offsetBy: count, limitedBy: str.endIndex) ?? str.endIndex
             return String(str[startIndex..<endIndex])
@@ -346,7 +346,7 @@
         }
 
         if uri == "/country.txt" {
-            let text = capitals[String(uri.characters.dropFirst())]!
+            let text = capitals[String(uri.dropFirst())]!
             return _HTTPResponse(response: .OK, headers: "Content-Length: \(text.data(using: .utf8)!.count)", body: text)
         }
 
@@ -356,7 +356,7 @@
         }
 
 	if uri == "/UnitedStates" {
-            let value = capitals[String(uri.characters.dropFirst())]!
+            let value = capitals[String(uri.dropFirst())]!
             let text = request.getCommaSeparatedHeaders()
             let host = request.headers[1].components(separatedBy: " ")[1]
             let ip = host.components(separatedBy: ":")[0]
@@ -366,7 +366,7 @@
             let httpResponse = _HTTPResponse(response: .REDIRECT, headers: "Location: http://\(newHost + "/" + value)", body: text)
             return httpResponse 
         }
-        return _HTTPResponse(response: .OK, body: capitals[String(uri.characters.dropFirst())]!) 
+        return _HTTPResponse(response: .OK, body: capitals[String(uri.dropFirst())]!)
     }
 
     func stop() {
diff --git a/TestFoundation/TestDecimal.swift b/TestFoundation/TestDecimal.swift
index 3abe3b9..3839d53 100644
--- a/TestFoundation/TestDecimal.swift
+++ b/TestFoundation/TestDecimal.swift
@@ -260,7 +260,7 @@
                     var failed: Bool = false
                     var count = 0
                     let SIG_FIG = 14
-                    for (a, b) in zip(answerDescription.characters, approximationDescription.characters) {
+                    for (a, b) in zip(answerDescription, approximationDescription) {
                         if a != b {
                             failed = true
                             break
diff --git a/TestFoundation/TestNSString.swift b/TestFoundation/TestNSString.swift
index b3787bf..33177ca 100644
--- a/TestFoundation/TestNSString.swift
+++ b/TestFoundation/TestNSString.swift
@@ -1298,11 +1298,11 @@
     // To determine the expected results, compare grapheme clusters,
     // scalar-to-scalar, of the NFD form of the strings.
     let lhsNFDGraphemeClusters =
-        lhs.decomposedStringWithCanonicalMapping.characters.map {
+        lhs.decomposedStringWithCanonicalMapping.map {
             Array(String($0).unicodeScalars)
     }
     let rhsNFDGraphemeClusters =
-        rhs.decomposedStringWithCanonicalMapping.characters.map {
+        rhs.decomposedStringWithCanonicalMapping.map {
             Array(String($0).unicodeScalars)
     }
     let expectHasPrefix = lhsNFDGraphemeClusters.starts(
diff --git a/TestFoundation/TestPipe.swift b/TestFoundation/TestPipe.swift
index e73405e..29f346b 100644
--- a/TestFoundation/TestPipe.swift
+++ b/TestFoundation/TestPipe.swift
@@ -35,7 +35,7 @@
         aPipe.fileHandleForWriting.write(stringAsData!)
         
         // Then read it out again
-        let data = aPipe.fileHandleForReading.readData(ofLength: text.characters.count)
+        let data = aPipe.fileHandleForReading.readData(ofLength: text.count)
         
         // Confirm that we did read data
         XCTAssertNotNil(data)
diff --git a/TestFoundation/TestStream.swift b/TestFoundation/TestStream.swift
index 9517db1..783b5e3 100644
--- a/TestFoundation/TestStream.swift
+++ b/TestFoundation/TestStream.swift
@@ -135,7 +135,7 @@
             XCTAssertEqual(Stream.Status.open, outputStream!.streamStatus)
             let result: Int? = outputStream?.write(encodedData, maxLength: encodedData.count)
             outputStream?.close()
-            XCTAssertEqual(myString.characters.count, result)
+            XCTAssertEqual(myString.count, result)
             XCTAssertEqual(Stream.Status.closed, outputStream!.streamStatus)
             removeTestFile(filePath!)
         } else {
@@ -154,7 +154,7 @@
         let result: Int? = outputStream.write(encodedData, maxLength: encodedData.count)
         outputStream.close()
         XCTAssertEqual(Stream.Status.closed, outputStream.streamStatus)
-        XCTAssertEqual(myString.characters.count, result)
+        XCTAssertEqual(myString.count, result)
         XCTAssertEqual(NSString(bytes: &buffer, length: buffer.count, encoding: String.Encoding.utf8.rawValue), NSString(string: myString))
     }
     
@@ -169,7 +169,7 @@
             XCTAssertEqual(Stream.Status.open, outputStream!.streamStatus)
             let result: Int? = outputStream?.write(encodedData, maxLength: encodedData.count)
             outputStream?.close()
-            XCTAssertEqual(myString.characters.count, result)
+            XCTAssertEqual(myString.count, result)
             XCTAssertEqual(Stream.Status.closed, outputStream!.streamStatus)
             removeTestFile(filePath!)
         } else {
@@ -186,7 +186,7 @@
         outputStream.open()
         XCTAssertEqual(Stream.Status.open, outputStream.streamStatus)
         let result: Int? = outputStream.write(encodedData, maxLength: encodedData.count)
-        XCTAssertEqual(myString.characters.count, result)
+        XCTAssertEqual(myString.count, result)
         //verify the data written
         let dataWritten  = outputStream.property(forKey: Stream.PropertyKey.dataWrittenToMemoryStreamKey)
         if let nsdataWritten = dataWritten as? NSData {