7
7
See http://swift.org/LICENSE.txt for license information
8
8
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9
9
*/
10
+ #if os(Windows)
11
+ import Foundation
12
+ #endif
10
13
11
14
/// Represents an absolute file system path, independently of what (or whether
12
15
/// anything at all) exists at that path in the file system at any given time.
@@ -370,6 +373,10 @@ private struct PathImpl: Hashable {
370
373
/// string consisting of just `.` if there is no directory part (which is
371
374
/// the case if and only if there is no path separator).
372
375
fileprivate var dirname : String {
376
+ #if os(Windows)
377
+ let dir = string. deletingLastPathComponent
378
+ return dir == " " ? " . " : dir
379
+ #else
373
380
// FIXME: This method seems too complicated; it should be simplified,
374
381
// if possible, and certainly optimized (using UTF8View).
375
382
// Find the last path separator.
@@ -385,6 +392,7 @@ private struct PathImpl: Hashable {
385
392
// Otherwise, it's the string up to (but not including) the last path
386
393
// separator.
387
394
return String ( string. prefix ( upTo: idx) )
395
+ #endif
388
396
}
389
397
390
398
fileprivate var basename : String {
@@ -561,11 +569,13 @@ private func mayNeedNormalization(absolute string: String) -> Bool {
561
569
///
562
570
/// The normalization rules are as described for the AbsolutePath struct.
563
571
private func normalize( absolute string: String ) -> String {
572
+ #if os(Windows)
573
+ return string. standardizingPath
574
+ #else
564
575
precondition ( string. first == " / " , " Failure normalizing \( string) , absolute paths should start with '/' " )
565
576
566
577
// At this point we expect to have a path separator as first character.
567
578
assert ( string. first == " / " )
568
-
569
579
// Fast path.
570
580
if !mayNeedNormalization( absolute: string) {
571
581
return string
@@ -621,13 +631,17 @@ private func normalize(absolute string: String) -> String {
621
631
622
632
// Use the result as our stored string.
623
633
return result
634
+ #endif
624
635
}
625
636
626
637
/// Private function that normalizes and returns a relative string. Asserts
627
638
/// that `string` does not start with a path separator.
628
639
///
629
640
/// The normalization rules are as described for the AbsolutePath struct.
630
641
private func normalize( relative string: String ) -> String {
642
+ #if os(Windows)
643
+ return string. standardizingPath
644
+ #else
631
645
precondition ( string. first != " / " )
632
646
633
647
// FIXME: Here we should also keep track of whether anything actually has
@@ -688,4 +702,5 @@ private func normalize(relative string: String) -> String {
688
702
689
703
// If the result is empty, return `.`, otherwise we return it as a string.
690
704
return result. isEmpty ? " . " : result
705
+ #endif
691
706
}
0 commit comments