67 Commits

Author SHA1 Message Date
Tony Parker
9218bda96a
Only use the underscored utf16 function when we are a contiguous UTF8 string. (#685)
Co-authored-by: Jeremy Schonfeld <jschonfeld@apple.com>
2024-06-17 15:23:13 -07:00
Charles Hu
8976fc4fd6
Introduce Cmake support for SwiftFoundation (#573) 2024-06-16 22:21:28 -07:00
Jeremy Schonfeld
b1acbafbca
Fix calloc build failure on macOS (#680) 2024-06-14 09:47:54 -07:00
Tony Parker
e53bc1ccd4
Unify UTF16 conversion path for String (#670) 2024-06-13 10:00:04 -07:00
Saleem Abdulrasool
654fa54be7
FoundationEssentials: canonicalise the arc separator more aggressively (#669)
When trying to get the file system representation of a string, we may
have previously used `appendingPathComponent(_:)` which will have used
the incorrect separator. Ensure that all the separators are properly
converted prior to returning the path.
2024-06-07 17:16:39 -07:00
Tony Parker
7997b425ed
String(bytes:encoding:) should not skip BOM on UTF16 to UTF8 conversion (#663) 2024-06-07 09:25:49 -07:00
Saleem Abdulrasool
50d7537507
FoundationEssentials: handle canonical and non-canonical paths (#668)
In the case that the path is canonicalised, the `/` would be replaced
with `\`. The leading `\` would interfere with our ability to recognise
the absolute path representation and thus get the wrong response.
2024-06-07 09:20:18 -07:00
Tony Parker
5357a58046
Add compatibility path for String(bytes:encoding:) (#651) 2024-06-04 09:01:24 -07:00
Saleem Abdulrasool
08d50c1caa
FoundationEssentials: correct path canonicalisation handling on Windows (#639)
* FoundationEssentials: correct path canonicalisation handling on Windows

Strip the extended path prefix for bypassing the Win32 API layer. This
is guaranteed to be prefixed on strings as per the documentation.

* Update Sources/FoundationEssentials/String/String+Path.swift

Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>

---------

Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>
2024-05-30 13:12:47 -07:00
Saleem Abdulrasool
f29e378d8f
FoundationEssentials: strip leading / (#627)
When creating a file system representation from the path, we need to
strip the leading `/` which is added for the RFC representation of the
Windows path. Without this, the C runtime will fail with an invalid
argument error. Unfortunately this regresses the test suite by causing a
hang.
2024-05-29 13:29:15 -07:00
Tony Parker
65c6532a8e
See if String(contentsOf:) family can be implemented directly in Swift (#622) 2024-05-20 11:16:56 -07:00
Charles Hu
b762e818f5
Improve String+Path performance by removing Regex (#612)
Reimplement `String._transmutingCompressingSlashes` and `pathHasDotDot` without using Regex. Reimplementing this method without Regex allows us to:
- Reduce the additional frames at launch since the Swift rewrite (Regex parsing brings in tons of frames)
- Not having to load additional dylib (`libswift_StringProcessing)
2024-05-15 13:00:05 -07:00
Jonathan Flat
e991656bd0
URL.init(filePath:) should resolve against the base URL before checking if the file is a directory (#606) 2024-05-13 17:22:28 -07:00
Saleem Abdulrasool
8bdf040aef
(128006071) FoundationEssentials: simplify path normalization (#603)
We would previously conditionally call `GetFullPathNameW` and do string
manipulations for normalising the path. Instead, always call
`GetFullPathNameW` to normalise the path as per Windows' rules. This
more importantly will collapse runs of the arc separator, which is
crucial when using extended paths as the NT path form must always use
the normalised paths or the access will fail.
2024-05-13 13:05:31 -07:00
Jonathan Flat
4a526630f8
Support Windows URL paths in FoundationEssentials (#602) 2024-05-13 19:22:08 +00:00
Jeremy Schonfeld
f270f75171
(125852961) Use ICU-equivalent \b behavior with Regex for String.range(of:) (#590) 2024-05-07 15:58:49 -07:00
Jeremy Schonfeld
727bd07830
Utilize URL in FileManager (#589)
* Use URL in FileManager

* Fix warnings

* Fix build failures on Linux

* Remove Locale_ICU warning fix
2024-05-07 15:55:08 -07:00
Jonathan Flat
361efcf5fe
Port URL and URLComponents to swift-foundation (#586) 2024-05-06 09:51:18 -07:00
Saleem Abdulrasool
1dea76a35f
FoundationEssentials: correct an off-by-one error on Windows (#587)
The returned value in the success case does not account for the
terminating nul character, resulting in the value being 1 less than the
allocation required. This was causing a spurious failure and thus unable
to compute the location of the process.
2024-05-06 09:29:24 -07:00
Jeremy Schonfeld
a5f9a9431d
(122557036) Add autoreleasepool to __swiftFillFileSystemRepresentation (#574) 2024-05-01 14:13:17 -07:00
Jeremy Schonfeld
cd9c0da71b
(123921236) Implement ASCII encoding for String.data(using:) (#557)
* Implement ASCII encoding for String.data(using:)

* Add early check for allASCII if available

* Move from Collections API to stdlib API
2024-04-26 14:32:32 -07:00
Saleem Abdulrasool
f299bde9df
FoundationEssentials: implement some path utilities on Windows (#547)
Add an implementation for querying the user's home directory and for
resolving symbolic links on Windows.
2024-04-17 14:26:00 -07:00
Jeremy Schonfeld
ad1c3fc865
(123127047) Remove _foundation_essentials_feature_enabled
Co-authored-by: Tony Parker <anthony.parker@apple.com>
2024-04-09 16:06:05 -07:00
Saleem Abdulrasool
3a7c84e3f6
FoundationEssentials: add withNTPathRepresentation (#531)
This helper allows us to convert paths to the NT path representation.
The NT Path representation is important for internal usage as it allows
us to bypass the `MAX_PATH` (261) limit for Win32 APIs. In order to do
this, we simply escape the string with the NT prefix (`\\?\`) which
requires that the path is normalised (uses `\` rather than `/`) and
generally should be an absolute path. Using the NT path allows us to use
the fully supported 32k character path length of the NT kernel.

Co-authored-by: Alexander Smarus <bender@readdle.com>
Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>
2024-04-09 14:22:32 -07:00
Jeremy Schonfeld
61f97b6e52
(123444217) Avoid filling FSR with partial scalars on failure 2024-04-09 09:29:54 -07:00
Saleem Abdulrasool
9491cce69c
FoundationEssentials: add some missing imports for Windows (#520)
This allows us to get further into building FoundationEssentials once
again on Windows. Much of the file system work has resulted in this
module no longer being viable on Windows and will need to be replaced to
allow building on Windows which does not have the `fts` APIs.
2024-03-29 14:19:23 -07:00
Tony Parker
ec730c21f0
Build swift-corelibs-foundation as a package on top of swift-foundation (#514)
* Provide public access for some internal functions, to enable swift-corelibs-foundation

* Add access to TimeZone internals for swift-corelibs-foundation

* Fix default TimeZone for Linux

* Remove unneeded private entry point

* Do not use a recursive definition of description for String.Encoding

* Merge in some WASI changes and other Data fixes

* Add temporary initializer to the stub URL

* Remove Hashable conformance for CocoaError. This allows userInfo to be Any instead of AnyHashable

* Remove some protocols which depend on NSError from swift-foundation -- they will live in swift-corelibs-foundation

* Adjust the debug description of the GMT ICU calendar to be a little less implementation-specific

* Use an English-only description for string encodings, for compatibility with existing SCL-F clients

* Use a more compatible definition of a backstop value for Bundle
2024-03-28 14:55:31 -07:00
Jeremy Schonfeld
544ec6c816
(123714904) Ensure stable home directory for processes calling seteuid
* (123714904) Ensure stable home directory for processes calling seteuid

* (123714904) Add comments
2024-03-21 13:16:19 -07:00
Tony Parker
0be1758b4f Various fixes to make PropertyListEncoder and PropertyListDecoder build cross-platform 2024-03-06 15:57:33 -08:00
Jeremy Schonfeld
e5211f2926
(122981400) Standardize on using internal import 2024-03-06 13:42:02 -08:00
Jeremy Schonfeld
61835133f8
(123525912) FileManager should standardize home directory paths (#452) 2024-03-06 11:47:21 -08:00
Jeremy Schonfeld
0e23938f4b
(123636178) Resolving symlinks can remove prefix from path 2024-02-26 12:58:09 -08:00
Jeremy Schonfeld
5b06c5d5ac
(123102499) FileManager's setAttributes:forItemAtPath: is unnecessarily slow
* (123102499) Swift implementation of setAttributes:forItemAtPath: is slower than the old ObjC implementation

* Move relevant key list to static array

* Fix build failure
2024-02-20 11:46:54 -08:00
Jeremy Schonfeld
b8ef4ce99c
(122106445) Exclude some paths from automount standardization
* (122106445) Exclude some paths from automount standardization

* Fix linux build failure
2024-02-19 13:04:07 -08:00
Jeremy Schonfeld
039c4d683c
Efficient buffer size calculation for String file system representation
* Use smaller buffer for file system representation

* Reword scalars -> code-units

Co-authored-by: Karl <5254025+karwa@users.noreply.github.com>

---------

Co-authored-by: Karl <5254025+karwa@users.noreply.github.com>
2024-02-13 13:21:16 -08:00
Jeremy Schonfeld
39dc85e87c
(122536991) File system representations should not be limited to PATH_MAX 2024-02-09 16:33:38 -08:00
Jeremy Schonfeld
33856a556d
(120741818) Port FileManager to swift-foundation
* (120741818) Port FileManager to swift-foundation

* (120741818) Fix linux test failures

* (120741818) Fix build failures
2024-02-09 15:03:43 -08:00
Jonathan Flat
f907600758
(121150146) String.lastPathComponent should return last non-empty component
Co-authored-by: Jonathan Flat <jflat@apple.com>
2024-02-07 14:13:53 -08:00
Jeremy Schonfeld
a163cbe9a8
(122199292) Guard against UTF8 buffers from large strings 2024-02-02 16:37:59 -08:00
Tina Liu
b316fad5dc
Remove _foundation_essentials_feature_enabled guard in FOUNDATION_FRAMEWORK (#387)
Enable the code paths guarded behind the feature flag unconditionally now that the feature flag has been enabled for quite a while now.
2024-01-29 11:12:11 -08:00
Tony Parker
4499edd7b1
Implement Data reading and writing (#377)
* Implement Data reading and writing

* Use swift-foundation-local for dependency name in benchmark
2024-01-17 13:04:41 -08:00
Jeremy Schonfeld
7f1bcff03b
Fix an off by one error in Strings file system representation 2024-01-04 13:42:50 -08:00
Jeremy Schonfeld
ea334c656b
(118839391) Implement file system representation for String
* (118839391) Implement file system representation for String

* (118839391) Fix some build issues

* (118839391) Fix embedded nulls and precomposed characters
2023-12-14 10:02:20 -08:00
Charles Hu
7272a47c0b
Refactoring some import conditions (#298) 2023-10-25 15:11:37 -07:00
Tony Parker
85ddb1373c
Add SortDescriptor and SortComparator (#288)
* Port SortDescriptor and SortComparator to FoundationEssentials

rdar://116408260

* Update availability
2023-10-25 10:34:17 -07:00
Tina Liu
62500a5d79
Follow up for #278 : make the required function from FoundationEssentials package so we can use it from FoundationI18n (#286)
* Follow up for #278 : make the required function from FoundationEssentials `package` so we can use it from FoundationI18n

* Workaround TAPI error by removing the default arguments
2023-10-06 16:03:57 -07:00
Tony Parker
3d52b255b7
Move String additions from _FoundationInternals to FoundationEssentials + package (#282) 2023-10-04 16:38:28 -07:00
Tony Parker
9fae9b1c6b
Revert "Move String additions from _FoundationInternals to FoundationEssentials + package" (#281)
This reverts commit 3a17834c7f397c9b83085008cad99eca7d7f3735.
2023-10-04 15:39:55 -07:00
Tony Parker
3a17834c7f
Move String additions from _FoundationInternals to FoundationEssentials + package 2023-10-04 15:24:17 -07:00
Jeremy Schonfeld
13f712d7d3
(115217483) paragraphRange(for:) can attempt to form invalid string indices
* (115217483) paragraphRange(for:) can attempt to form invalid string indices

* (115217483) Address off-by-one logic error in separator matching
2023-09-15 13:45:48 -07:00