Skip to content

Commit 7520ded

Browse files
authored
Merge pull request #1171 from spevans/pr_characters_deprecate
2 parents b26818d + 266b466 commit 7520ded

12 files changed

+52
-58
lines changed

Foundation/HTTPCookie.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ open class HTTPCookie : NSObject {
249249
_domain = canonicalDomain
250250

251251
if let
252-
secureString = properties[.secure] as? String, !secureString.characters.isEmpty
252+
secureString = properties[.secure] as? String, !secureString.isEmpty
253253
{
254254
_secure = true
255255
} else {
@@ -267,8 +267,7 @@ open class HTTPCookie : NSObject {
267267
_version = version
268268

269269
if let portString = properties[.port] as? String, _version == 1 {
270-
_portList = portString.characters
271-
.split(separator: ",")
270+
_portList = portString.split(separator: ",")
272271
.flatMap { Int(String($0)) }
273272
.map { NSNumber(value: $0) }
274273
} else {
@@ -361,8 +360,8 @@ open class HTTPCookie : NSObject {
361360
}
362361
//Remove the final trailing semicolon and whitespace
363362
if ( cookieString.length > 0 ) {
364-
cookieString.characters.removeLast()
365-
cookieString.characters.removeLast()
363+
cookieString.removeLast()
364+
cookieString.removeLast()
366365
}
367366
return ["Cookie": cookieString]
368367
}
@@ -624,7 +623,7 @@ fileprivate extension String {
624623
}
625624

626625
func insertComma(at index:Int) -> String {
627-
return String(self.characters.prefix(index)) + "," + String(self.characters.suffix(self.characters.count-index))
626+
return String(self.prefix(index)) + "," + String(self.suffix(self.count-index))
628627
}
629628
}
630629

Foundation/JSONSerialization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ internal extension JSONSerialization {
286286
//MARK: - JSONSerializer
287287
private struct JSONWriter {
288288

289-
private let maxUIntLength = String(describing: UInt.max).characters.count
290-
private let maxIntLength = String(describing: Int.max).characters.count
289+
private let maxUIntLength = String(describing: UInt.max).count
290+
private let maxIntLength = String(describing: Int.max).count
291291
var indent = 0
292292
let pretty: Bool
293293
let sortedKeys: Bool

Foundation/NSPathUtilities.swift

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,16 @@ public func NSTemporaryDirectory() -> String {
3535

3636
internal extension String {
3737

38-
internal var _startOfLastPathComponent : String.CharacterView.Index {
38+
internal var _startOfLastPathComponent : String.Index {
3939
precondition(!hasSuffix("/") && length > 1)
4040

41-
let characterView = characters
42-
let startPos = characterView.startIndex
43-
let endPos = characterView.endIndex
44-
var curPos = endPos
41+
let startPos = startIndex
42+
var curPos = endIndex
4543

4644
// Find the beginning of the component
4745
while curPos > startPos {
48-
let prevPos = characterView.index(before: curPos)
49-
if characterView[prevPos] == "/" {
46+
let prevPos = index(before: curPos)
47+
if self[prevPos] == "/" {
5048
break
5149
}
5250
curPos = prevPos
@@ -55,19 +53,16 @@ internal extension String {
5553

5654
}
5755

58-
internal var _startOfPathExtension : String.CharacterView.Index? {
56+
internal var _startOfPathExtension : String.Index? {
5957
precondition(!hasSuffix("/"))
6058

61-
let characterView = self.characters
62-
let endPos = characterView.endIndex
63-
var curPos = endPos
64-
59+
var curPos = endIndex
6560
let lastCompStartPos = _startOfLastPathComponent
6661

6762
// Find the beginning of the extension
6863
while curPos > lastCompStartPos {
69-
let prevPos = characterView.index(before: curPos)
70-
let char = characterView[prevPos]
64+
let prevPos = index(before: curPos)
65+
let char = self[prevPos]
7166
if char == "/" {
7267
return nil
7368
} else if char == "." {
@@ -125,7 +120,7 @@ internal extension String {
125120
}
126121
}
127122
if stripTrailing && result.length > 1 && result.hasSuffix("/") {
128-
result.remove(at: result.characters.index(before: result.characters.endIndex))
123+
result.remove(at: result.index(before: result.endIndex))
129124
}
130125
return result
131126
}
@@ -181,7 +176,7 @@ public extension NSString {
181176
return fixedSelf
182177
}
183178

184-
return String(fixedSelf.characters.suffix(from: fixedSelf._startOfLastPathComponent))
179+
return String(fixedSelf.suffix(from: fixedSelf._startOfLastPathComponent))
185180
}
186181

187182
public var deletingLastPathComponent : String {
@@ -202,7 +197,7 @@ public extension NSString {
202197

203198
// all common cases
204199
case let startOfLast:
205-
return String(fixedSelf.characters.prefix(upTo: fixedSelf.index(before: startOfLast)))
200+
return String(fixedSelf.prefix(upTo: fixedSelf.index(before: startOfLast)))
206201
}
207202
}
208203

@@ -236,7 +231,7 @@ public extension NSString {
236231
}
237232
}
238233
if stripTrailing && result.hasSuffix("/") {
239-
result.remove(at: result.characters.index(before: result.characters.endIndex))
234+
result.remove(at: result.index(before: result.endIndex))
240235
}
241236
return result
242237
}
@@ -265,7 +260,7 @@ public extension NSString {
265260
}
266261

267262
if let extensionPos = fixedSelf._startOfPathExtension {
268-
return String(fixedSelf.characters.suffix(from: extensionPos))
263+
return String(fixedSelf.suffix(from: extensionPos))
269264
} else {
270265
return ""
271266
}
@@ -277,7 +272,7 @@ public extension NSString {
277272
return fixedSelf
278273
}
279274
if let extensionPos = (fixedSelf._startOfPathExtension) {
280-
return String(fixedSelf.characters.prefix(upTo: fixedSelf.characters.index(before: extensionPos)))
275+
return String(fixedSelf.prefix(upTo: fixedSelf.index(before: extensionPos)))
281276
} else {
282277
return fixedSelf
283278
}
@@ -297,9 +292,9 @@ public extension NSString {
297292
return _swiftObject
298293
}
299294

300-
let endOfUserName = _swiftObject.characters.index(of: "/") ?? _swiftObject.endIndex
301-
let startOfUserName = _swiftObject.characters.index(after: _swiftObject.characters.startIndex)
302-
let userName = String(_swiftObject.characters[startOfUserName..<endOfUserName])
295+
let endOfUserName = _swiftObject.index(of: "/") ?? _swiftObject.endIndex
296+
let startOfUserName = _swiftObject.index(after: _swiftObject.startIndex)
297+
let userName = String(_swiftObject[startOfUserName..<endOfUserName])
303298
let optUserName: String? = userName.isEmpty ? nil : userName
304299

305300
guard let homeDir = NSHomeDirectoryForUser(optUserName) else {
@@ -478,7 +473,7 @@ public extension NSString {
478473
return strings.first
479474
}
480475

481-
var sequences = strings.map({ $0.characters.makeIterator() })
476+
var sequences = strings.map({ $0.makeIterator() })
482477
var prefix: [Character] = []
483478
loop: while true {
484479
var char: Character? = nil
@@ -490,8 +485,8 @@ public extension NSString {
490485
}
491486

492487
if char != nil {
493-
let lhs = caseSensitive ? char : String(char!).lowercased().characters.first!
494-
let rhs = caseSensitive ? c : String(c).lowercased().characters.first!
488+
let lhs = caseSensitive ? char : String(char!).lowercased().first!
489+
let rhs = caseSensitive ? c : String(c).lowercased().first!
495490
if lhs != rhs {
496491
break loop
497492
}

Foundation/NSStringAPI.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ extension String {
292292
aString,
293293
options: mask,
294294
range: _toNSRange(
295-
range ?? self.characters.startIndex..<self.characters.endIndex
295+
range ?? self.startIndex..<self.endIndex
296296
),
297297
locale: locale?._bridgeToObjectiveC()
298298
)
@@ -1060,7 +1060,7 @@ extension String {
10601060
from: aSet,
10611061
options: mask,
10621062
range: _toNSRange(
1063-
aRange ?? self.characters.startIndex..<self.characters.endIndex
1063+
aRange ?? self.startIndex..<self.endIndex
10641064
)
10651065
)
10661066
)
@@ -1120,7 +1120,7 @@ extension String {
11201120
of: aString,
11211121
options: mask,
11221122
range: _toNSRange(
1123-
searchRange ?? self.characters.startIndex..<self.characters.endIndex
1123+
searchRange ?? self.startIndex..<self.endIndex
11241124
),
11251125
locale: locale
11261126
)
@@ -1343,7 +1343,7 @@ extension String {
13431343
with: replacement,
13441344
options: options,
13451345
range: _toNSRange(
1346-
searchRange ?? self.characters.startIndex..<self.characters.endIndex
1346+
searchRange ?? self.startIndex..<self.endIndex
13471347
)
13481348
)
13491349
: _ns.replacingOccurrences(of: target, with: replacement)

Foundation/NSURL.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal func _pathComponents(_ path: String?) -> [String]? {
3434
if p.length == 0 {
3535
return result
3636
} else {
37-
let characterView = p.characters
37+
let characterView = p
3838
var curPos = characterView.startIndex
3939
let endPos = characterView.endIndex
4040
if characterView[curPos] == "/" {
@@ -738,7 +738,7 @@ extension NSURL {
738738
}
739739
}
740740
if stripTrailing && result.hasSuffix("/") {
741-
result.remove(at: result.characters.index(before: result.characters.endIndex))
741+
result.remove(at: result.index(before: result.endIndex))
742742
}
743743
return result
744744
}
@@ -757,7 +757,7 @@ extension NSURL {
757757
return fixedSelf
758758
}
759759

760-
return String(fixedSelf.characters.suffix(from: fixedSelf._startOfLastPathComponent))
760+
return String(fixedSelf.suffix(from: fixedSelf._startOfLastPathComponent))
761761
}
762762

763763
open var pathExtension: String? {
@@ -769,7 +769,7 @@ extension NSURL {
769769
}
770770

771771
if let extensionPos = fixedSelf._startOfPathExtension {
772-
return String(fixedSelf.characters.suffix(from: extensionPos))
772+
return String(fixedSelf.suffix(from: extensionPos))
773773
} else {
774774
return ""
775775
}

Foundation/ProcessInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ open class ProcessInfo: NSObject {
9292
return OperatingSystemVersion(majorVersion: fallbackMajor, minorVersion: fallbackMinor, patchVersion: fallbackPatch)
9393
}
9494

95-
let versionComponents = productVersion._swiftObject.characters.split(separator: ".").map(String.init).flatMap({ Int($0) })
95+
let versionComponents = productVersion._swiftObject.split(separator: ".").map(String.init).flatMap({ Int($0) })
9696
let majorVersion = versionComponents.dropFirst(0).first ?? fallbackMajor
9797
let minorVersion = versionComponents.dropFirst(1).first ?? fallbackMinor
9898
let patchVersion = versionComponents.dropFirst(2).first ?? fallbackPatch

Foundation/XMLNode.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ open class XMLNode: NSObject, NSCopying {
421421
var entityChars: [Character] = []
422422
var inEntity = false
423423
var startIndex = 0
424-
for (index, char) in string.characters.enumerated() {
424+
for (index, char) in string.enumerated() {
425425
if char == "&" {
426426
inEntity = true
427427
startIndex = index
@@ -440,7 +440,7 @@ open class XMLNode: NSObject, NSCopying {
440440
}
441441
}
442442

443-
var result: [Character] = Array(string.characters)
443+
var result: [Character] = Array(string)
444444
let doc = _CFXMLNodeGetDocument(_xmlNode)!
445445
for (range, entity) in entities {
446446
var entityPtr = _CFXMLGetDocEntity(doc, entity)
@@ -452,7 +452,7 @@ open class XMLNode: NSObject, NSCopying {
452452
}
453453
if let validEntity = entityPtr {
454454
let replacement = _CFXMLCopyEntityContent(validEntity)?._swiftObject ?? ""
455-
result.replaceSubrange(range, with: replacement.characters)
455+
result.replaceSubrange(range, with: replacement)
456456
} else {
457457
result.replaceSubrange(range, with: []) // This appears to be how Darwin Foundation does it
458458
}

TestFoundation/HTTPServer.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class _TCPSocket {
100100
}
101101

102102
func split(_ str: String, _ count: Int) -> [String] {
103-
return stride(from: 0, to: str.characters.count, by: count).map { i -> String in
103+
return stride(from: 0, to: str.count, by: count).map { i -> String in
104104
let startIndex = str.index(str.startIndex, offsetBy: i)
105105
let endIndex = str.index(startIndex, offsetBy: count, limitedBy: str.endIndex) ?? str.endIndex
106106
return String(str[startIndex..<endIndex])
@@ -346,7 +346,7 @@ public class TestURLSessionServer {
346346
}
347347

348348
if uri == "/country.txt" {
349-
let text = capitals[String(uri.characters.dropFirst())]!
349+
let text = capitals[String(uri.dropFirst())]!
350350
return _HTTPResponse(response: .OK, headers: "Content-Length: \(text.data(using: .utf8)!.count)", body: text)
351351
}
352352

@@ -356,7 +356,7 @@ public class TestURLSessionServer {
356356
}
357357

358358
if uri == "/UnitedStates" {
359-
let value = capitals[String(uri.characters.dropFirst())]!
359+
let value = capitals[String(uri.dropFirst())]!
360360
let text = request.getCommaSeparatedHeaders()
361361
let host = request.headers[1].components(separatedBy: " ")[1]
362362
let ip = host.components(separatedBy: ":")[0]
@@ -366,7 +366,7 @@ public class TestURLSessionServer {
366366
let httpResponse = _HTTPResponse(response: .REDIRECT, headers: "Location: http://\(newHost + "/" + value)", body: text)
367367
return httpResponse
368368
}
369-
return _HTTPResponse(response: .OK, body: capitals[String(uri.characters.dropFirst())]!)
369+
return _HTTPResponse(response: .OK, body: capitals[String(uri.dropFirst())]!)
370370
}
371371

372372
func stop() {

TestFoundation/TestDecimal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class TestDecimal: XCTestCase {
260260
var failed: Bool = false
261261
var count = 0
262262
let SIG_FIG = 14
263-
for (a, b) in zip(answerDescription.characters, approximationDescription.characters) {
263+
for (a, b) in zip(answerDescription, approximationDescription) {
264264
if a != b {
265265
failed = true
266266
break

TestFoundation/TestNSString.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,11 +1298,11 @@ func checkHasPrefixHasSuffix(_ lhs: String, _ rhs: String, _ stack: [UInt]) -> I
12981298
// To determine the expected results, compare grapheme clusters,
12991299
// scalar-to-scalar, of the NFD form of the strings.
13001300
let lhsNFDGraphemeClusters =
1301-
lhs.decomposedStringWithCanonicalMapping.characters.map {
1301+
lhs.decomposedStringWithCanonicalMapping.map {
13021302
Array(String($0).unicodeScalars)
13031303
}
13041304
let rhsNFDGraphemeClusters =
1305-
rhs.decomposedStringWithCanonicalMapping.characters.map {
1305+
rhs.decomposedStringWithCanonicalMapping.map {
13061306
Array(String($0).unicodeScalars)
13071307
}
13081308
let expectHasPrefix = lhsNFDGraphemeClusters.starts(

TestFoundation/TestPipe.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class TestPipe : XCTestCase {
3535
aPipe.fileHandleForWriting.write(stringAsData!)
3636

3737
// Then read it out again
38-
let data = aPipe.fileHandleForReading.readData(ofLength: text.characters.count)
38+
let data = aPipe.fileHandleForReading.readData(ofLength: text.count)
3939

4040
// Confirm that we did read data
4141
XCTAssertNotNil(data)

TestFoundation/TestStream.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class TestStream : XCTestCase {
135135
XCTAssertEqual(Stream.Status.open, outputStream!.streamStatus)
136136
let result: Int? = outputStream?.write(encodedData, maxLength: encodedData.count)
137137
outputStream?.close()
138-
XCTAssertEqual(myString.characters.count, result)
138+
XCTAssertEqual(myString.count, result)
139139
XCTAssertEqual(Stream.Status.closed, outputStream!.streamStatus)
140140
removeTestFile(filePath!)
141141
} else {
@@ -154,7 +154,7 @@ class TestStream : XCTestCase {
154154
let result: Int? = outputStream.write(encodedData, maxLength: encodedData.count)
155155
outputStream.close()
156156
XCTAssertEqual(Stream.Status.closed, outputStream.streamStatus)
157-
XCTAssertEqual(myString.characters.count, result)
157+
XCTAssertEqual(myString.count, result)
158158
XCTAssertEqual(NSString(bytes: &buffer, length: buffer.count, encoding: String.Encoding.utf8.rawValue), NSString(string: myString))
159159
}
160160

@@ -169,7 +169,7 @@ class TestStream : XCTestCase {
169169
XCTAssertEqual(Stream.Status.open, outputStream!.streamStatus)
170170
let result: Int? = outputStream?.write(encodedData, maxLength: encodedData.count)
171171
outputStream?.close()
172-
XCTAssertEqual(myString.characters.count, result)
172+
XCTAssertEqual(myString.count, result)
173173
XCTAssertEqual(Stream.Status.closed, outputStream!.streamStatus)
174174
removeTestFile(filePath!)
175175
} else {
@@ -186,7 +186,7 @@ class TestStream : XCTestCase {
186186
outputStream.open()
187187
XCTAssertEqual(Stream.Status.open, outputStream.streamStatus)
188188
let result: Int? = outputStream.write(encodedData, maxLength: encodedData.count)
189-
XCTAssertEqual(myString.characters.count, result)
189+
XCTAssertEqual(myString.count, result)
190190
//verify the data written
191191
let dataWritten = outputStream.property(forKey: Stream.PropertyKey.dataWrittenToMemoryStreamKey)
192192
if let nsdataWritten = dataWritten as? NSData {

0 commit comments

Comments
 (0)