Skip to content
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

[SR-9749] The encodedOffset of String.Index has been changed to either UTF-8 or UTF-16. #52180

norio-nomura opened this issue Jan 24, 2019 · 5 comments


Copy link

norio-nomura commented Jan 24, 2019

Previous ID SR-9749
Radar rdar://problem/47605131
Original Reporter @norio-nomura
Type Bug
Status Resolved
Resolution Done


Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee @milseman
Priority Medium

md5: 66ece592c380ddd277127ea29c649351

Issue Description:

The problem is:

  1. Before merging [String] Use a UTF-8 representation for native strings #20315, The encodedOffset of String.Index was specified as UTF-16 offset, and it actually worked as expected.

    /// The offset into a string's UTF-16 encoding for this index.
    @inlinable // FIXME(sil-serialize-all)
    public var encodedOffset : Int {

    /// Creates a new index at the specified UTF-16 offset.
    /// - Parameter offset: An offset in UTF-16 code units.
    @inlinable // FIXME(sil-serialize-all)
    public init(encodedOffset offset: Int) {

  2. A lot of codes were written that expect that behavior (including swift-corelibs-foundation)
    e.g. codes using encodedOffset in Swift on GitHub can be found:

  3. However, the change is not written in changelog etc., and it is understood only from the description of UTF-16 deleted from each documentation comment. In fact, swift-corelibs-foundation did not recognize that change was necessary, which caused SR-9454.

I think that some countermeasures are necessary:

  • [MUST] Behavior changes should be documented (eg within changelog).

  • [MAY] Some code change
    Mark init(encodedOffset:) and encodedOffset as deprecated
    Introduce new property exposing encode information(UTF-8 or UTF-16) to String

/cc: @milseman

Copy link

milseman mannequin commented Jan 25, 2019


Will need release-noting as well.

Copy link
Contributor Author

norio-nomura commented Jan 25, 2019

I am very happy that it seems to be adopting the best solution (I did not write on the issue) that I imagined! 😃

Copy link
Contributor Author

norio-nomura commented Feb 12, 2019

Another example to fix an issue caused by wrong usage of encodedOffset.

Copy link

milseman mannequin commented Apr 10, 2019

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant