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.RootfromComponent- Provides a much clearer separation of API
- Allows for many corner cases to be handled by the type system
-
FilePath.Rootcan in the future be a namespace for Windows root analysis
-
FilePath.ComponentViewis now also aRangeReplaceableCollection- Standard Swift algorithms operate over homogeneous components of a path
-
FilePath.Componenthas aKindenum, illustrating mutual exclusivity -
relativePathwas renamedremovingRoot()- Consistent with other "removing" APIs
- More precise on Windows (where a rooted path can be relative)
- Rename
basename/dirnametolastComponentandremovingLastComponent()- Include
@available(unavailable, renamed:)entries for discoverability -
removeLastis nowremoveLastComponent(it doesn't remove a root)
- Include
-
appendoverhaul:-
appendnow only takesComponents, so there are no roots involved -
appendoverload taking aStringfor common stringy treatment of paths- Ignores a leading separator if needed
- Will be preferred for string literal arguments
-
pushis introduced for the commoncd-like semantics- aka
joinin Python,pushin Rust,Combinein C#,appendin C++17
- aka
-
-
ing variants of everything introduced for expression chaining
-
__consumingand__ownedannotations added to make these efficient
-
- Add
lexicallyResolving(), a secure-ish append over untrusted subpaths - Add
CTypesempy enum to serve as a namespace for C typealiases-
PlatformCharandPlatformUnicodeEncodingare 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