Skip to content

Commit 977207a

Browse files
committed
Remove use of NSString.replacingOccurrences(of:with:)
Prefer to use `String.replacing(_:with:)` instead of the `NSString` operations for the strings. This should avoid an unnecessary use of Foundation API and a dispatch to the `NSString` API. Bump the minimum platform version to 10.13 to deal with the API availability in the standard library.
1 parent 15840e4 commit 977207a

File tree

11 files changed

+14
-14
lines changed

11 files changed

+14
-14
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]
7575
let package = Package(
7676
name: "SwiftPM",
7777
platforms: [
78-
.macOS(.v12),
78+
.macOS(.v13),
7979
.iOS(.v15)
8080
],
8181
products:

Sources/Basics/FileSystem/AbsolutePath.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ extension AbsolutePath {
321321

322322
extension AbsolutePath {
323323
public var escapedPathString: String {
324-
self.pathString.replacingOccurrences(of: "\\", with: "\\\\")
324+
self.pathString.replacing("\\", with: "\\\\")
325325
}
326326
}
327327

Sources/Basics/FileSystem/NativePathExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension AbsolutePath {
2020
return URL(fileURLWithPath: self.pathString).withUnsafeFileSystemRepresentation {
2121
let repr = String(cString: $0!)
2222
if escaped {
23-
return repr.replacingOccurrences(of: "\\", with: "\\\\")
23+
return repr.replacing("\\", with: "\\\\")
2424
}
2525
return repr
2626
}

Sources/Basics/Netrc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public struct NetrcParser {
133133
var trimmedCommentsText = text
134134
matches.forEach {
135135
trimmedCommentsText = trimmedCommentsText
136-
.replacingOccurrences(of: nsString.substring(with: $0.range), with: "")
136+
.replacing(nsString.substring(with: $0.range), with: "")
137137
}
138138
return trimmedCommentsText
139139
}

Sources/Basics/Sandbox.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ extension AbsolutePath {
231231
/// Private computed property that returns a version of the path as a string quoted for use as a subpath in a .sb sandbox profile.
232232
fileprivate var quotedAsSubpathForSandboxProfile: String {
233233
"\"" + self.pathString
234-
.replacingOccurrences(of: "\\", with: "\\\\")
235-
.replacingOccurrences(of: "\"", with: "\\\"")
234+
.replacing("\\", with: "\\\\")
235+
.replacing("\"", with: "\\\"")
236236
+ "\""
237237
}
238238
}

Sources/Commands/Utilities/DOTManifestSerializer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public struct DOTManifestSerializer {
3838

3939
/// Quote the name and escape the quotes and backslashes
4040
func quoteName(_ name: String) -> String {
41-
return "\"" + name.replacingOccurrences(of: "\"", with: "\\\"")
42-
.replacingOccurrences(of: "\\", with: "\\\\") + "\""
41+
return "\"" + name.replacing("\"", with: "\\\"")
42+
.replacing("\\", with: "\\\\") + "\""
4343
}
4444

4545
public mutating func writeDOT(to stream: OutputByteStream) {

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
961961

962962
var environment = ProcessEnv.vars
963963
#if os(Windows)
964-
let windowsPathComponent = runtimePath.pathString.replacingOccurrences(of: "/", with: "\\")
964+
let windowsPathComponent = runtimePath.pathString.replacing("/", with: "\\")
965965
environment["Path"] = "\(windowsPathComponent);\(environment["Path"] ?? "")"
966966
#endif
967967

Sources/PackageLoading/ModuleMapGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public let moduleMapFilename = "module.modulemap"
1919

2020
extension AbsolutePath {
2121
fileprivate var moduleEscapedPathString: String {
22-
return self.pathString.replacingOccurrences(of: "\\", with: "\\\\")
22+
return self.pathString.replacing("\\", with: "\\\\")
2323
}
2424
}
2525

Sources/PackageModel/ManifestSourceGeneration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,8 @@ extension TargetBuildSettingDescription.Kind {
684684
extension String {
685685
fileprivate var quotedForPackageManifest: String {
686686
return "\"" + self
687-
.replacingOccurrences(of: "\\", with: "\\\\")
688-
.replacingOccurrences(of: "\"", with: "\\\"")
687+
.replacing("\\", with: "\\\\")
688+
.replacing("\"", with: "\\\"")
689689
+ "\""
690690
}
691691
}

Sources/PackageRegistry/RegistryClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,7 @@ extension HTTPClientHeaders {
21582158
return nil
21592159
}
21602160

2161-
return parts[1].replacingOccurrences(of: "\"", with: "")
2161+
return parts[1].replacing("\"", with: "")
21622162
}
21632163
}
21642164

Sources/SourceControl/GitRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ public final class GitRepository: Repository, WorkingCheckout {
771771
}
772772

773773
return stringPaths.map(output.split(separator: "\n").map {
774-
let string = String($0).replacingOccurrences(of: "\\\\", with: "\\")
774+
let string = String($0).replacing("\\\\", with: "\\")
775775
if string.utf8.first == UInt8(ascii: "\"") {
776776
return String(string.dropFirst(1).dropLast(1))
777777
}

0 commit comments

Comments
 (0)