Skip to content

Commit 150013e

Browse files
committed
SwiftDocC: handle arc separator on Windows
The file system representation of the URL is OS dependent. Since we do not have an easy to get the file system representation of a relative path, perform the arc separator translation explicitly through string manipulation. This helps fix a few errors on Windows.
1 parent b98a915 commit 150013e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Sources/SwiftDocC/Servers/FileServer.swift

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ public class MemoryFileServerProvider: FileServerProvider {
198198
@discardableResult
199199
public func addFile(path: String, data: Data) -> Bool {
200200
guard !path.isEmpty else { return false }
201-
let trimmed = path.trimmingCharacters(in: slashCharSet)
201+
var trimmed = path.trimmingCharacters(in: slashCharSet)
202+
#if os(Windows)
203+
trimmed = trimmed.replacingOccurrences(of: #"/"#, with: #"\"#)
204+
#endif
202205
files[trimmed] = data
203206
return true
204207
}
@@ -210,7 +213,10 @@ public class MemoryFileServerProvider: FileServerProvider {
210213
- returns: The data matching the url, if possible.
211214
*/
212215
public func data(for path: String) -> Data? {
213-
let trimmed = path.trimmingCharacters(in: slashCharSet)
216+
var trimmed = path.trimmingCharacters(in: slashCharSet)
217+
#if os(Windows)
218+
trimmed = trimmed.replacingOccurrences(of: #"/"#, with: #"\"#)
219+
#endif
214220
return files[trimmed]
215221
}
216222

@@ -247,7 +253,12 @@ public class MemoryFileServerProvider: FileServerProvider {
247253
- parameter path: The path used to match the files.
248254
*/
249255
public func removeAllFiles(in subPath: String) {
250-
let trimmed = subPath.trimmingCharacters(in: slashCharSet).appending("/")
256+
var trimmed = subPath.trimmingCharacters(in: slashCharSet)
257+
#if os(Windows)
258+
trimmed = trimmed.appending(#"\"#)
259+
#else
260+
trimmed = trimmed.appending(#"/"#)
261+
#endif
251262
for key in files.keys where key.hasPrefix(trimmed) {
252263
files.removeValue(forKey: key)
253264
}

0 commit comments

Comments
 (0)