Skip to content

[5.1][String.Index] Deprecate encodedOffset var/init #23081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2019

Conversation

milseman
Copy link
Member

@milseman milseman commented Mar 5, 2019

5.1 cherry-pick of #22695

rdar://problem/48583657

String.Index has an encodedOffset-based initializer and computed
property that exists for serialization purposes. It was documented as
UTF-16 in the SE proposal introducing it, which was String's
underlying encoding at the time, but the dream of String even then was
to abstract away whatever encoding happend to be used.

Serialization needs an explicit encoding for serialized indices to
make sense: the offsets need to align with the view. With String
utilizing UTF-8 encoding for native contents in Swift 5, serialization
isn't necessarily the most efficient in UTF-16.

Furthermore, the majority of usage of encodedOffset in the wild is
buggy and operates under the assumption that a UTF-16 code unit was a
Swift Character, which isn't even valid if the String is known to be
all-ASCII (because CR-LF).

This change introduces a pair of semantics-preserving alternatives to
encodedOffset that explicitly call out the UTF-16 assumption. These
serve as a gentle off-ramp for current mis-uses of encodedOffset.
@milseman
Copy link
Member Author

milseman commented Mar 5, 2019

@swift-ci please test and merge

@milseman milseman changed the title [String.Index] Deprecate encodedOffset var/init [5.1][String.Index] Deprecate encodedOffset var/init Mar 5, 2019
@swift-ci swift-ci merged commit 6e6b7e4 into swiftlang:swift-5.1-branch Mar 5, 2019
@milseman milseman deleted the 5_1_en_gadus_offset branch March 7, 2019 21:06
@milseman
Copy link
Member Author

milseman commented Mar 8, 2019

rdar://problem/48583657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants