@@ -2033,9 +2033,7 @@ extension URL {
2033
2033
var filePathArray = Array ( utf8)
2034
2034
filePathArray [ 1 ] = UInt8 ( ascii: " : " )
2035
2035
filePathArray. insert ( UInt8 ( ascii: " \\ " ) , at: 0 )
2036
- filePath = String ( unsafeUninitializedCapacity: filePathArray. count) { buffer in
2037
- buffer. initialize ( fromContentsOf: filePathArray)
2038
- }
2036
+ filePath = String ( decoding: filePathArray, as: UTF8 . self)
2039
2037
} else {
2040
2038
filePath = " \\ " + filePath
2041
2039
}
@@ -2082,14 +2080,7 @@ extension URL {
2082
2080
2083
2081
#if os(Windows)
2084
2082
let slash = UInt8 ( ascii: " \\ " )
2085
- var hostName : String ?
2086
- var hostEnd = path. startIndex
2087
- if path. utf8. starts ( with: [ slash, slash] ) {
2088
- let hostStart = path. utf8. index ( path. utf8. startIndex, offsetBy: 2 )
2089
- hostEnd = path [ hostStart... ] . utf8. firstIndex { $0 == slash || $0 == UInt8 ( ascii: " / " ) } ?? path. endIndex
2090
- hostName = String ( path [ hostStart..< hostEnd] )
2091
- }
2092
- var filePath = path [ hostEnd... ] . replacing ( UInt8 ( ascii: " / " ) , with: slash)
2083
+ var filePath = path. replacing ( UInt8 ( ascii: " / " ) , with: slash)
2093
2084
#else
2094
2085
let slash = UInt8 ( ascii: " / " )
2095
2086
var filePath = path
@@ -2104,21 +2095,12 @@ extension URL {
2104
2095
#endif
2105
2096
2106
2097
func absoluteFilePath( ) -> String {
2107
- #if os(Windows)
2108
- if let hostName {
2109
- return #"\\"# + hostName + filePath
2110
- }
2111
- #endif
2112
2098
guard !isAbsolute, let baseURL else {
2113
2099
return filePath
2114
2100
}
2115
2101
#if os(Windows)
2116
2102
let urlPath = filePath. replacing ( UInt8 ( ascii: " \\ " ) , with: UInt8 ( ascii: " / " ) )
2117
- var mergedPath = baseURL. mergedPath ( for: urlPath) . replacing ( UInt8 ( ascii: " / " ) , with: UInt8 ( ascii: " \\ " ) )
2118
- if let baseHost = baseURL. host ( percentEncoded: false ) , !baseHost. isEmpty {
2119
- return #"\\"# + baseHost + mergedPath
2120
- }
2121
- return mergedPath
2103
+ return baseURL. mergedPath ( for: urlPath) . replacing ( UInt8 ( ascii: " / " ) , with: UInt8 ( ascii: " \\ " ) )
2122
2104
#else
2123
2105
return baseURL. mergedPath ( for: filePath)
2124
2106
#endif
@@ -2159,15 +2141,7 @@ extension URL {
2159
2141
var components = URLComponents ( )
2160
2142
if isAbsolute {
2161
2143
components. scheme = " file "
2162
- #if os(Windows)
2163
- if let hostName {
2164
- components. host = hostName
2165
- } else {
2166
- components. encodedHost = " "
2167
- }
2168
- #else
2169
2144
components. encodedHost = " "
2170
- #endif
2171
2145
}
2172
2146
components. path = filePath
2173
2147
@@ -2181,17 +2155,15 @@ extension URL {
2181
2155
2182
2156
private func appending< S: StringProtocol > ( path: S , directoryHint: DirectoryHint , encodingSlashes: Bool ) -> URL {
2183
2157
#if os(Windows)
2184
- var path = path. replacing ( UInt8 ( ascii: " \\ " ) , with: UInt8 ( ascii: " / " ) )
2158
+ let path = path. replacing ( UInt8 ( ascii: " \\ " ) , with: UInt8 ( ascii: " / " ) )
2185
2159
#endif
2186
2160
guard var pathToAppend = Parser . percentEncode ( path, component: . path) else {
2187
2161
return self
2188
2162
}
2189
2163
if encodingSlashes {
2190
2164
var utf8 = Array ( pathToAppend. utf8)
2191
2165
utf8. replace ( [ UInt8 ( ascii: " / " ) ] , with: [ UInt8 ( ascii: " % " ) , UInt8 ( ascii: " 2 " ) , UInt8 ( ascii: " F " ) ] )
2192
- pathToAppend = String ( unsafeUninitializedCapacity: utf8. count) { buffer in
2193
- buffer. initialize ( fromContentsOf: utf8)
2194
- }
2166
+ pathToAppend = String ( decoding: utf8, as: UTF8 . self)
2195
2167
}
2196
2168
2197
2169
let slash = UInt8 ( ascii: " / " )
0 commit comments