45 Commits

Author SHA1 Message Date
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
Tina Liu
9df5dc6518
(112770879) “Washington, D.c.” capitalized incorrectly (#212)
* (112770879) “Washington, D.c.” capitalized incorrectly

Theoretically "." is a case-ignorable character, so "D.C." is conceptually the same as "DC", whose capitalized mapping would be "Dc". This behavior doesn't seem to align with real-world use cases well though. Workaround this by splitting the string with "." and titlecasing each substring individually.

* (112770879) “Washington, D.c.” capitalized incorrectly, cont.

For FoundationPreview: Move String comparison utilities from FoundationEssentials fo _FoundationInternals so they can be accessed from FoundationInternalization too.
2023-07-31 10:51:34 -07:00
Tina Liu
1402b8cff1
rdar://111921940 (SEED: Swift runtime' string parsing behavior regressed in Dawnburst.) (#198)
We had a fast path implemented incorrectly: We search the UTF8 code unit whenever possible, and convert the found UTF8 index back to String index. If the conversion fails, i.e. when the found UTF8 index does not fall on a character boundary, we simply bail and return nil. The correct implementation should be advancing the slice from the point of failure and keeping searching.

But we don't really need this fast path here as we already have another one that skips string transformation inside the helper function. Let's just remove this.
2023-07-13 08:34:19 -07:00
Joey
32bf8bc848
Documentation - Consistency Fixes (#187)
* Documentation for attributed string's number formatting.

* Documentation - Typos & Consistency Fixes
2023-06-29 10:55:29 -07:00
Charles Hu
14eb5a1f60
Addressed compiler warnings and updated the incorrect license headers (#190) 2023-06-28 11:00:02 -07:00
Karoy Lorentey
85d1021e51
rdar://109907151&110477287 Fix StringProtocol.lineRange(for:)/paragraphRange(for:) (#174)
These started by converting `self` into a `String`. This lead to crashes when `self` happened to be a Substring, as the input range isn’t necessarily a valid index range in the resulting string in that case.

While I’m here, review related helper functions to improve performance and to avoid more correctness issues.
2023-06-09 14:21:12 -07:00
Tina Liu
7f8f56cf95
Work towards: Stop calling into Foundation's implementation (#153)
* Use stdlib's `replacing(:with:)` instead of NSString's `replacingOccurrences(of:with:)`
* Move internal implementation of `_range(of:anchored:backwards:)` to _FoundationInternals. Update callsites to use this instead of NSString's `range(of:)` implementation.
Note: we should consider moving to stdlib's `firstRange(of:)` once rdar://109910336 is addressed.
* Add tests for _range(of:anchored:backwards:)
2023-05-30 15:53:28 -07:00
Tina Liu
7348693927
FoundationPreview: Stop relying on CharacterSet for trimming whitespace (#145)
* Generalize trimming function to take a predicate block. Move this function to FoundationEssentials.

* Call `_trimmingWhitespaces()` instead of through CharacterSet.

* Review feedback: rename the function to whitespace from whitespaces

* Add tests

* Standarize whitespacing and remove spaces in empty line
2023-05-26 13:11:35 -07:00
Tina Liu
4ca2c1c986
Remove String._Encoding (#132)
* Remove String._Encoding

Previously we added a new type `String._Encoding` for FoundationPreview to mirror Foundation framework's `String.Encoding` to work around Clang importer's ambiguous lookup issue. It turns out that the new type isn't needed for this workaround. Adding a typealias itself is sufficient.

* String.Encoding can conform to Hashable universally
2023-05-18 09:27:49 -07:00
Tina Liu
3aa00e5c3e
Revert "Create FoundationInternals, an internal module to host shared files used by FoundationInternationalization and FoundationEssentials (#101)" (#115)
* Revert "Create FoundationInternals, an internal module to host shared files used by FoundationInternationalization and FoundationEssentials (#101)"

This reverts commit 8f08a649db1f3eb31593cdae7a30c5e95cb614a7.

* Reapply fb718cd3fb9f058a5fd6d736cec9c2b99d6f7dc6 fix to the other restored LockedState
2023-05-11 15:19:01 -07:00
Tina Liu
8f08a649db
Create FoundationInternals, an internal module to host shared files used by FoundationInternationalization and FoundationEssentials (#101)
* Create FoundationInternals, an internal module to host shared files used by FoundationInternationalization and FoundationEssentials

- Modules will access FoundationInternals types with `package import FoundationInternals`. This is currently an experimental feature of `AccessLevelOnImport`.
- Move `LockedState` to FoundationInternals and publicize functions needed by other modules.
2023-05-10 12:16:20 -07:00
Guillaume Lessard
5c9bdf6205
Fix Memory Binding Issues (#94)
* fix memory binding

* use `load(as:)` instead of binding memory

* Use temporary binding rather than `bindMemory`

* use `load(as:)` and `storeBytes(of:as:)` as appropriate

* use temporary binding rather than binding assertions

* add a note about index validation
2023-05-09 13:47:26 -07:00
Leonardo da Silva
d267340e84
fix formatting (#86) 2023-05-01 09:49:54 -07:00
Alexander Cyon
09606b457d
Fix typos (#68) 2023-04-29 06:28:00 -07:00
Charles Hu
c01e9dadee
rdar://107955097 (FoundationPreview: Batch move string API (continued)) (#34)
* rdar://107955097 (FoundationPreview: Batch move string API (continued))

- Move localized uppercase and lowercase to FoundationLocalization
- if-def out of CharacterSet from FoundationPreview. It's not implemented at all there, and having a no-op stub is misleading

* rdar://107955097 (FoundationPreview: Batch move string API (continued))

- Move components separated by string and range of string functions

* rdar://107955097 (FoundationPreview: Batch move string API (continued))

Enable snake case options for JSON encoder and decoder. We haven't been able to enable this option because it needed `CharacterSet`, which hasn't been properly implemented for FoundationPreview. Now that we have `BuiltInUnicodeScalarSet`, which mirrors `CharacterSet`, we can switch to that and enable the options.

* rdar://107955097 (FoundationPreview: Batch move string API (continued))

- Move `StringProtocol.lineRange(for:)` and `paragraphRange(for:)` to FoundationEssentials
- Rename String+Regex.swift to RegexPatternCache.swift
- Consolidate extensions on various String family members and remove one redundant swift file

---------

Co-authored-by: I-Ting Tina Liu <iting_liu@apple.com>
2023-04-17 18:23:51 -07:00
Charles Hu
e2c177e867 Rebased on top of the new String APIs 2023-03-29 09:56:22 -07:00
Tina Liu
2f2ae679f6 rdar://107156343 (Rebased JSONEncoder on top of new String changes) 2023-03-29 09:56:15 -07:00
Charles Hu
34c45c169c rdar://107156343 (Move JSONEncoder to FoundationPreview) 2023-03-29 09:56:00 -07:00