Version 2 of this proposal can be found here. This thread was tremendously helpful and I want to thank everyone who took the time to review and comment on this API.
Changes:
- Spin off
FilePath.Root
fromComponent
- Provides a much clearer separation of API
- Allows for many corner cases to be handled by the type system
-
FilePath.Root
can in the future be a namespace for Windows root analysis
-
FilePath.ComponentView
is now also aRangeReplaceableCollection
- Standard Swift algorithms operate over homogeneous components of a path
-
FilePath.Component
has aKind
enum, illustrating mutual exclusivity -
relativePath
was renamedremovingRoot()
- Consistent with other "removing" APIs
- More precise on Windows (where a rooted path can be relative)
- Rename
basename
/dirname
tolastComponent
andremovingLastComponent()
- Include
@available(unavailable, renamed:)
entries for discoverability -
removeLast
is nowremoveLastComponent
(it doesn't remove a root)
- Include
-
append
overhaul:-
append
now only takesComponent
s, so there are no roots involved -
append
overload taking aString
for common stringy treatment of paths- Ignores a leading separator if needed
- Will be preferred for string literal arguments
-
push
is introduced for the commoncd
-like semantics- aka
join
in Python,push
in Rust,Combine
in C#,append
in C++17
- aka
-
-
ing variants of everything introduced for expression chaining
-
__consuming
and__owned
annotations added to make these efficient
-
- Add
lexicallyResolving()
, a secure-ish append over untrusted subpaths - Add
CTypes
empy enum to serve as a namespace for C typealiases-
PlatformChar
andPlatformUnicodeEncoding
are nested insideCTypes
- Allows us to add more C types without polluting global namespace
-
- Added deferred/future-work section about working with paths from another platform