Skip to content

Commit 207ae0e

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 cefff2b commit 207ae0e

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
@@ -69,7 +69,7 @@ let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]
6969
let package = Package(
7070
name: "SwiftPM",
7171
platforms: [
72-
.macOS(.v12),
72+
.macOS(.v13),
7373
.iOS(.v15)
7474
],
7575
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 func escapedPathString() -> String {
324-
self.pathString.replacingOccurrences(of: "\\", with: "\\\\")
324+
self.pathString.replacing("\\", with: "\\\\")
325325
}
326326
}
327327

Sources/Basics/NativePathExtensions.swift

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

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
@@ -223,8 +223,8 @@ extension AbsolutePath {
223223
/// Private computed property that returns a version of the path as a string quoted for use as a subpath in a .sb sandbox profile.
224224
fileprivate var quotedAsSubpathForSandboxProfile: String {
225225
"\"" + self.pathString
226-
.replacingOccurrences(of: "\\", with: "\\\\")
227-
.replacingOccurrences(of: "\"", with: "\\\"")
226+
.replacing("\\", with: "\\\\")
227+
.replacing("\"", with: "\\\"")
228228
+ "\""
229229
}
230230
}

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
@@ -766,7 +766,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
766766
// Run the compiled manifest.
767767
var environment = ProcessEnv.vars
768768
#if os(Windows)
769-
let windowsPathComponent = runtimePath.pathString.replacingOccurrences(of: "/", with: "\\")
769+
let windowsPathComponent = runtimePath.pathString.replacing("/", with: "\\")
770770
environment["Path"] = "\(windowsPathComponent);\(environment["Path"] ?? "")"
771771
#endif
772772

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
@@ -681,8 +681,8 @@ extension TargetBuildSettingDescription.Kind {
681681
extension String {
682682
fileprivate var quotedForPackageManifest: String {
683683
return "\"" + self
684-
.replacingOccurrences(of: "\\", with: "\\\\")
685-
.replacingOccurrences(of: "\"", with: "\\\"")
684+
.replacing("\\", with: "\\\\")
685+
.replacing("\"", with: "\\\"")
686686
+ "\""
687687
}
688688
}

Sources/PackageRegistry/RegistryClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2165,7 +2165,7 @@ extension HTTPClientHeaders {
21652165
return nil
21662166
}
21672167

2168-
return parts[1].replacingOccurrences(of: "\"", with: "")
2168+
return parts[1].replacing("\"", with: "")
21692169
}
21702170
}
21712171

Sources/SourceControl/GitRepository.swift

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

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

0 commit comments

Comments
 (0)