Skip to content

Commit 0e39f4f

Browse files
authored
Merge pull request #865 from compnerd/paths
TestUtilities: add path utilities
2 parents 40aabaa + d9b39c9 commit 0e39f4f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===---------- PathExtensions.swift - Driver Testing Extensions ----------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Foundation
14+
import TSCBasic
15+
16+
extension String {
17+
public func escaped() -> Self {
18+
#if os(Windows)
19+
return self.replacingOccurrences(of: "\\", with: "\\\\")
20+
#else
21+
return self
22+
#endif
23+
}
24+
25+
public func nativePathString() -> Self {
26+
return URL(fileURLWithPath: self).withUnsafeFileSystemRepresentation {
27+
String(cString: $0!)
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)