Skip to content

Commit d437b38

Browse files
committed
Apply review feedback
1 parent 68fe5cc commit d437b38

File tree

5 files changed

+16
-41
lines changed

5 files changed

+16
-41
lines changed

Sources/System/FilePath/FilePathComponents.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ extension FilePath: _PlatformStringable {
199199

200200
}
201201

202-
// TODO(root): Re-think these initializers. We want them to be conv
203-
204202
extension FilePath.Component {
205203
// The index of the `.` denoting an extension
206204
internal func _extensionIndex() -> SystemString.Index? {

Sources/System/FilePath/FilePathParsing.swift

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ extension FilePath {
158158
if writeIdx != relStart {
159159
let priorComponent = _parseComponent(priorTo: writeIdx)
160160

161-
// FIXME: it's not up until writeIdx because separator,
162-
// parseComponent should give the component...
163161
if !_isParentDirectory(priorComponent) {
164162
writeIdx = priorComponent.lowerBound
165163
readIdx = nextStart
@@ -182,8 +180,6 @@ extension FilePath {
182180

183181
assert(readIdx == _storage.endIndex && readIdx >= writeIdx)
184182
if readIdx != writeIdx {
185-
// TODO: Why was it everything after writeIdx?
186-
// storage.removeSubrange(storage.index(after: writeIdx)...)
187183
_storage.removeSubrange(writeIdx...)
188184
_removeTrailingSeparator()
189185
}
@@ -275,24 +271,6 @@ extension FilePath.ComponentView {
275271
internal var _relativeStart: SystemString.Index {
276272
_path._relativeStart
277273
}
278-
279-
internal func parseComponentStart(
280-
endingAt i: SystemString.Index
281-
) -> SystemString.Index {
282-
if i == _relativeStart, i != _path._storage.startIndex {
283-
return _path._storage.startIndex
284-
}
285-
var i = i
286-
if i != _path._storage.endIndex {
287-
assert(isSeparator(_path._storage[i]))
288-
i = _path._storage.index(before: i)
289-
}
290-
var slice = _path._storage[..<i]
291-
while let c = slice.last, !isSeparator(c) {
292-
slice.removeLast()
293-
}
294-
return slice.endIndex
295-
}
296274
}
297275

298276
extension SystemString {
@@ -370,7 +348,7 @@ extension FilePath {
370348
}
371349

372350
// Perform an append, inseting a separator if needed.
373-
// Note tha this will not check whether `content` is a root
351+
// Note that this will not check whether `content` is a root
374352
internal mutating func _append(unchecked content: Slice<SystemString>) {
375353
assert(FilePath(SystemString(content)).root == nil)
376354
if content.isEmpty { return }

Sources/System/FilePath/FilePathSyntax.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,13 @@ extension FilePath {
305305
/// replace the extension.
306306
///
307307
/// Examples:
308-
/// * `/tmp/foo.txt => txt`
309-
/// * `/Appliations/Foo.app/ => app`
310-
/// * `/Appliations/Foo.app/bar.txt => txt`
311-
/// * `/tmp/foo.tar.gz => gz`
312-
/// * `/tmp/.hidden => nil`
313-
/// * `/tmp/.hidden. => ""`
314-
/// * `/tmp/.. => nil`
308+
/// * `/tmp/foo.txt => txt`
309+
/// * `/Applications/Foo.app/ => app`
310+
/// * `/Applications/Foo.app/bar.txt => txt`
311+
/// * `/tmp/foo.tar.gz => gz`
312+
/// * `/tmp/.hidden => nil`
313+
/// * `/tmp/.hidden. => ""`
314+
/// * `/tmp/.. => nil`
315315
///
316316
/// Example:
317317
///
@@ -391,12 +391,10 @@ extension FilePath {
391391
/// Returns a copy of `self` in lexical-normal form, that is `.` and `..`
392392
/// components have been collapsed lexically (i.e. without following
393393
/// symlinks). See `lexicallyNormalize`
394-
public var lexicallyNormal: FilePath {
395-
__consuming get {
396-
var copy = self
397-
copy.lexicallyNormalize()
398-
return copy
399-
}
394+
public __consuming func lexicallyNormalized() -> FilePath {
395+
var copy = self
396+
copy.lexicallyNormalize()
397+
return copy
400398
}
401399

402400
/// Create a new `FilePath` by resolving `subpath` relative to `self`,
@@ -428,7 +426,7 @@ extension FilePath {
428426
public __consuming func lexicallyResolving(
429427
_ subpath: __owned FilePath
430428
) -> FilePath? {
431-
let subpath = subpath.removingRoot().lexicallyNormal
429+
let subpath = subpath.removingRoot().lexicallyNormalized()
432430
guard !subpath.isEmpty else { return self }
433431
guard subpath.components.first?.kind != .parentDirectory else {
434432
return nil

Tests/SystemTests/FilePathTests/FilePathExtras.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ extension FilePath {
5050
guard !other.isEmpty else { return true }
5151
guard !isEmpty else { return false }
5252

53-
let (selfLex, otherLex) = (self.lexicallyNormal, other.lexicallyNormal)
53+
let (selfLex, otherLex) =
54+
(self.lexicallyNormalized(), other.lexicallyNormalized())
5455
if otherLex.isAbsolute { return selfLex.starts(with: otherLex) }
5556

5657
// FIXME: Windows semantics with relative roots?

Tests/SystemTests/FilePathTests/FilePathSyntaxTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ extension SyntaxTestCase {
243243
copy.lexicallyNormalize()
244244
expectEqual(copy == path, path.isLexicallyNormal, "isLexicallyNormal")
245245
expectEqual(lexicallyNormalized, copy.description, "lexically normalized")
246-
expectEqual(copy, path.lexicallyNormal, "lexicallyNormal")
246+
expectEqual(copy, path.lexicallyNormalized(), "lexicallyNormal")
247247

248248
expectEqual(absolute, path.isAbsolute, "absolute")
249249
expectEqual(!absolute, path.isRelative, "!absolute")

0 commit comments

Comments
 (0)