@@ -15,16 +15,16 @@ import var Foundation.NSLocalizedDescriptionKey
15
15
public protocol Path : Hashable , Codable , CustomStringConvertible {
16
16
/// Underlying type, based on SwiftSystem.
17
17
var filepath : FilePath { get }
18
-
18
+
19
19
/// Public initializer from FilePath.
20
20
init ( _ filepath: FilePath )
21
-
21
+
22
22
/// Public initializer from String.
23
23
init ( _ string: String )
24
-
24
+
25
25
/// Convenience initializer that verifies that the path lexically.
26
26
init ( validating path: String ) throws
27
-
27
+
28
28
/// Normalized string representation (the normalization rules are described
29
29
/// in the documentation of the initializer). This string is never empty.
30
30
var pathString : String { get }
@@ -38,35 +38,35 @@ public protocol Path: Hashable, Codable, CustomStringConvertible {
38
38
39
39
/// Last path component (including the suffix, if any).
40
40
var basename : String { get }
41
-
41
+
42
42
/// Returns the basename without the extension.
43
43
var basenameWithoutExt : String { get }
44
-
44
+
45
45
/// Extension of the give path's basename. This follow same rules as
46
46
/// suffix except that it doesn't include leading `.` character.
47
47
var `extension` : String ? { get }
48
-
48
+
49
49
/// Suffix (including leading `.` character) if any. Note that a basename
50
50
/// that starts with a `.` character is not considered a suffix, nor is a
51
51
/// trailing `.` character.
52
52
var suffix : String ? { get }
53
-
53
+
54
54
/// True if the path is a root directory.
55
55
var isRoot : Bool { get }
56
-
56
+
57
57
/// Returns the path with an additional literal component appended.
58
58
///
59
59
/// This method accepts pseudo-path like '.' or '..', but should not contain "/".
60
60
func appending( component: String ) -> Self
61
-
61
+
62
62
/// Returns the relative path with additional literal components appended.
63
63
///
64
64
/// This method should only be used in cases where the input is guaranteed
65
65
/// to be a valid path component (i.e., it cannot be empty, contain a path
66
66
/// separator, or be a pseudo-path like '.' or '..').
67
67
func appending( components names: [ String ] ) -> Self
68
68
func appending( components names: String ... ) -> Self
69
-
69
+
70
70
/// Returns an array of strings that make up the path components of the
71
71
/// path. This is the same sequence of strings as the basenames of each
72
72
/// successive path component.
@@ -83,35 +83,35 @@ extension Path {
83
83
}
84
84
return filepath. string
85
85
}
86
-
86
+
87
87
public var root : String ? {
88
88
return filepath. root? . string
89
89
}
90
-
90
+
91
91
public var dirname : String {
92
92
let dirname = filepath. removingLastComponent ( ) . string
93
93
if dirname. isEmpty {
94
94
return " . "
95
95
}
96
96
return dirname
97
97
}
98
-
98
+
99
99
public var basename : String {
100
100
return filepath. lastComponent? . string ?? root ?? " . "
101
101
}
102
-
102
+
103
103
public var basenameWithoutExt : String {
104
104
return filepath. lastComponent? . stem ?? root ?? " . "
105
105
}
106
-
106
+
107
107
public var `extension` : String ? {
108
108
guard let ext = filepath. extension,
109
109
!ext. isEmpty else {
110
110
return nil
111
111
}
112
112
return filepath. extension
113
113
}
114
-
114
+
115
115
public var suffix : String ? {
116
116
if let ext = `extension` {
117
117
return " . \( ext) "
@@ -123,7 +123,7 @@ extension Path {
123
123
public var isRoot : Bool {
124
124
return filepath. isRoot
125
125
}
126
-
126
+
127
127
public func appending( component: String ) -> Self {
128
128
return Self ( filepath. appending (
129
129
FilePath . Component ( stringLiteral: component) ) )
@@ -137,15 +137,15 @@ extension Path {
137
137
public func appending( components names: String ... ) -> Self {
138
138
appending ( components: names)
139
139
}
140
-
140
+
141
141
public var components : [ String ] {
142
142
var components = filepath. components. map ( \. string)
143
143
if filepath. isRelative && components. isEmpty {
144
144
components. append ( " . " )
145
145
}
146
146
return components
147
147
}
148
-
148
+
149
149
public var description : String {
150
150
return pathString
151
151
}
@@ -424,7 +424,7 @@ extension FilePath {
424
424
}
425
425
#endif
426
426
}
427
-
427
+
428
428
var isRoot : Bool {
429
429
root != nil && components. isEmpty
430
430
}
0 commit comments