13 Commits

Author SHA1 Message Date
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