47 Commits

Author SHA1 Message Date
Jeremy Schonfeld
de6af532ad
AttributedString Index Validity APIs (#1177)
* AttributedString index validity APIs

* Move canImport(Synchronization) into function body

* Remove unnecessary bounds checks from validity expression

* Update FOUNDATION_FRAMEWORK code to provide Index versions
2025-02-28 12:17:21 -08:00
Jeremy Schonfeld
c2d30f4ab6
AttributeContainer Filtering (#1182) 2025-02-28 09:36:05 -08:00
Jeremy Schonfeld
3b31f75300
(140308690) AttributedString APIs for operations over noncontiguous ranges (#1145)
This PR implements the API changes proposed in SF-0014 by adding a new DiscontiguousAttributedSubstring type (the result of slicing an AttributedString with a RangeSet) which vends out slices of each underlying view, an upgraded Runs view which now handles discontiguous segments, and performs operations over the discontiguous subranges.
2025-02-17 10:48:14 -08:00
Jeremy Schonfeld
74275a96e8
(144239125) Re-add existing SPI for enumerating NSAttributedString.Key runs (#1162) 2025-02-05 15:12:28 -08:00
Jeremy Schonfeld
0fe74286a2
(143906360) AttributesString.Runs.subscript(nsAttributedStringKeys:) should accept array of keys rather than variadic (#1153) 2025-01-31 12:05:22 -08:00
Jeremy Schonfeld
7e083cdf64
Optimize removing nonexistent attributes in AttributedString (#1150) 2025-01-30 11:37:56 -08:00
Jeremy Schonfeld
8558978538
(140368780) Enable client iteration of AttributeScopes (#1093) 2025-01-24 17:21:37 -08:00
Jeremy Schonfeld
b01f9c6a27
Implement AttributedString UTF8 and UTF16 views (#1066)
* (13984100) Implement AttributedString UTF8 and UTF16 views

* Remove public initializers

* Update index movement preconditions
2024-12-17 14:22:16 -08:00
Jeremy Schonfeld
1fff4b72df
(139680932) NSRange to Range<AttributedString.Index> conversion should be relative to sliced boundaries (#1050) 2024-11-18 10:01:21 -08:00
Jeremy Schonfeld
b49bbc637a
Ensure empty AttributedSubstrings produce no runs (#996) 2024-11-01 10:21:12 -07:00
Jeremy Schonfeld
89129779c6
(136518115) Remove unused AttributedString initializers (#948)
Signed-off-by: Jeremy Schonfeld <jschonfeld@apple.com>
2024-09-26 14:34:22 -07:00
Jeremy Schonfeld
da80d51fa3
(134376602) Change @_nonSendable to unavailable extensions (#892) 2024-09-03 10:46:46 -07:00
Jeremy Schonfeld
b1716fe949
Re-add sendable annotations (#740)
* (131556645) Restore sendable annotations

* (131556645) Fix build failures
2024-07-18 09:15:47 -07:00
Karoy Lorentey
6236e84e45
Fix AttributedString slicing behavior on range expressions (#727)
`AttributedString` goes out of its way to emulate the stdlib’s behavior for `String` slicing. Unfortunately, it went a little overboard:

```swift
import Foundation

let str1 = "F\u{301}a\u{308}n\u{303}c\u{327}y\u{30a}" // "F́äñçẙ"
let str2 = AttributedString(str1)

let substr1 = str1[...str1.startIndex] // “F\u{301}”
let substr2 = str2[...str2.startIndex] // “F”
print(Array(substr1.unicodeScalars))
print(Array(substr2.unicodeScalars))
```

We expect slicing on range expressions to always produce  consistent results between `String` and `AttributedString`.

When slicing character-based string views on `…str.startIndex`, we naturally expect the range expression to cover the entire first `Character`, and that is precisely what `String` does.

`AttributedString`’s default view is not as obviously `Character`-based as `String` is, but emulating the stdlib’s behavior is much preferable than to allow such simple, character-aligned range expressions to slice the attributed string at random sub-character positions.
2024-07-11 14:54:36 -07:00
Charles Hu
8976fc4fd6
Introduce Cmake support for SwiftFoundation (#573) 2024-06-16 22:21:28 -07:00
Tony Parker
63be4bd898
Revert some Sendable fixes around KeyPath while we sort out a compiler bug with ABI stability (#679) 2024-06-14 09:58:41 -07:00
Tony Parker
caa08cf226
Enable complete concurrency checking in Foundation 2024-06-04 10:41:59 -07:00
Jeremy Schonfeld
bcd54e0881
Prepare for _FoundationCollections module name (#650)
* Prepare for _FoundationCollections module name

* Fix build failure
2024-06-03 18:25:52 -07:00
Hristo Staykov
554913c124
Introduce formatNumber attribute for attributed strings (#580)
rdar://122432849
2024-05-02 14:39:59 -07:00
Jeremy Schonfeld
de8c251f24
(118472879) Fix AttributedString.UnicodeScalarView.distance(from:to:) availability (#551) 2024-04-17 13:52:24 -07:00
Charles Hu
543bd69d7d
Rename DurationTimeFormatStyle and DurationUnitsFormatStyle to add Test suffix (#516)
resolves rdar://125511901, rdar://125569243
2024-03-28 15:53:29 -07:00
Jeremy Schonfeld
e5211f2926
(122981400) Standardize on using internal import 2024-03-06 13:42:02 -08:00
Jeremy Schonfeld
e5115b31db
(120011730) AttributedString --> NSAS conversion is expensive due to dictionary merging and setting empty attribute dictionaries 2024-01-02 09:56:08 -08:00
Jeremy Schonfeld
a1b890ce14
(118862703) AttributeScope cache does not correctly store negative results 2023-12-12 15:44:00 -08:00
Tony Parker
db3d0a4fcc
Add import for _dyld_image_count (#329) 2023-11-27 09:38:46 -08:00
Charles Hu
30bc5b99f2
Introduce Availability Macros for FoundationPreview (#279) 2023-10-04 14:44:37 -07:00
Tina Liu
0fe5c5fafa
Implement unlocalized range(of:) for AttributedString (#249)
* Implement unlocalized range(of:) for AttributedString

`String` has a natively-implemented `_range(of:options:)`. This PR implements `AttributedString`'s `range(of:options:)` with that when localization support is not needed.
Ideally we should implement this on `BigString` to avoid iterating through `Characters`, which is tracked as a future TODO.

This function takes a `Locale` argument, which isn't available in FoundationEssentials. We could move this to FoundationInternalization where `Locale` is defined, but some clients use it with `locale: nil` and do not need localized results. To make the best of this let's add a non-localized version for FoundationEssentials.

* Enable AttributedString.range(of:) when locale is nil
2023-10-03 12:13:20 -07:00
Tony Parker
b14c22bc84
Update availability to released OS versions (#271) 2023-09-26 12:52:12 -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
06ea8b042f
Start using Rope for attribute run storage (#166)
* rdar://108152217 Start using Rope for attribute run storage

- Replace `Array<_InternalRun>` with `Rope<_InternalRun>`.
- Fix semantics of AttributeRunBoundaries.character. It no longer pretends that attributes can be tied to grapheme clusters — that never actually worked properly, and it cannot be supported without breaking the intended use case.
- Remove cache of latest run position; log(n) might be fast enough that we don’t need to worry about that.
- Switch AttributedString.Guts members to take/return BigString.Index values, not AttributedString indices. This cuts down on constant back-and-forth conversions.
- Discard unused Guts members; update remaining mutation methods to follow Swift naming conventions.
- Stop using the `public extension` language misfeature.

* rdar://108152217 Apply notes from code review

AttributedString.CharacterView and AttributedString.UnicodeScalarView
did not use the right semantics in the case when the underlying text
was not touched. It’s okay in that case to not mutate text storage,
but we still want to override the attributes within the subrange as if
the client actually did replace text — as in, we want to use precisely
the same attribute storage for the range on both paths.

Also, make sure we correctly enforce attribute constraints in the
`!hasStringChanges` case, in both views.

* rdar://108152217 Fix logic error in AttributedString.Runs.subscript

(Discovered during code review.)

* rdar://108152217 Clean up CharacterView/UnicodeScalarView mutations & update failing test

* rdar://108152217 Apply review notes
2023-06-26 13:51:15 -07:00
Alejandro Alonso
8fc19313cd
FoundationEssentials: Use dlsym instead of _typeByName in Attribute scope lookup (#151)
* Use dlsym instead of _typeByName

* Don't use AppKit overlay location

* Remove unused subscript and make Darwin import public
2023-06-06 15:03:52 -07:00
Joey
b1e1c919eb
Documentation - Typos & Consistency Fixes (#88) 2023-05-31 11:44:55 -07:00
Jeremy Schonfeld
9c72d351d2
(105902981) Replace @_implementationOnly imports with package imports in FoundationPreview (#109) 2023-05-12 11:36:10 -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
Karoy Lorentey
c46afaf068
rdar://105027055: Improve AttributedString view slicing (#92)
* rdar://105027055: Do not use as-casts in specializations.

Introduce _specializingCast and use it instead of `as?`-casts inside
if ladders that implement generic specialization.

`as?` invokes undesirable runtime machinery such as bridging checks.

* rdar://105027055: Ensure AttributedString views have properly aligned bounds

* rdar://105027055: Implement index(_:offsetBy:limitedBy:) in AttributedString views
2023-05-08 11:17:35 -07:00
Jeremy Schonfeld
61ff810564
rdar://107768277 (AttributeScope.attributeKeyType(matching:) is fairly slow and is a bottleneck for AttributedString conversion) 2023-05-01 09:56:00 -07:00
Alexander Cyon
09606b457d
Fix typos (#68) 2023-04-29 06:28:00 -07:00
Hristo Staykov
fec24b0db1
rdar://108534616 (Rename agreeWithReplacement to agreeWithArgument) (#77)
We have agreed that `agreeWithArgument` sounds more intuitive to localizers than
`agreeWithReplacement`. This attribute hasn't been adopted internally yet, so we
can afford to rename it just before the SDK freeze.
2023-04-27 14:31:49 -07:00
Jeremy Schonfeld
985f782734
rdar://101354563 (Codable Support for Predicate)
* (101354563) Separate CodableWithConfiguration into standalone file

* (101354563) Update PredicateExpression archive formats

* (101354563) Codable Support for Predicate

* (101354563) Assert on unsupported keypaths
2023-04-26 12:57:40 -07:00
Karoy Lorentey
e9b2f68e8a
rdar://107778676 Stop vendoring the Collections package (#50)
* rdar://107778676 Stop vendoring the Collections package

* rdar://107778676 Fix test expectation

AttributedString.CharacterView needs to round all indices down to the
nearest Character boundary to avoid semantic issues with its
Collection conformance. This means that CharacterView slices can never
start or end in between Character boundaries.

* Remove a stray print statement
2023-04-25 13:44:02 -07:00
Jeremy Schonfeld
74559afbea
rdar://104093459 (Adopt the new Reflection Package to AttributedString) (#48) 2023-04-19 11:21:17 -07:00
Tony Parker
d1cc2ea0a2
Add some links to known issues to TODOs (#47) 2023-04-18 14:53:06 -07:00
Jeremy Schonfeld
82baceef48 rdar://100474708 (Make AttributedString Sendable) 2023-04-03 10:41:22 -07:00
Jeremy Schonfeld
99a3c9f4ad
(106775060) Add TODO notes around disabled tests and functionality 2023-03-23 13:26:07 -07:00
Jeremy Schonfeld
8ce51672b6
(106775060) Update AttributedString sources for compatibility with FoundationPreview 2023-03-23 13:26:07 -07:00
Jeremy Schonfeld
b03b3032d2
(106775060) Move AttributedString sources to FoundationPreview 2023-03-23 13:26:00 -07:00