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

Closed
norio-nomura opened this issue Jan 24, 2019 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@norio-nomura
Copy link
Contributor

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

swift-DEVELOPMENT-SNAPSHOT-2019-01-23-a
swift-5.0-DEVELOPMENT-SNAPSHOT-2019-01-23-a

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 {

    https://github.com/apple/swift/pull/20315/files#diff-8ec9c169d4bc3c678838b4067481979eL130

    /// 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) {

    https://github.com/apple/swift/pull/20315/files#diff-8ec9c169d4bc3c678838b4067481979eL106

  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: https://github.com/search?l=Swift&q=encodedOffset&type=Code

  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
    or
    Introduce new property exposing encode information(UTF-8 or UTF-16) to String

/cc: @milseman

@milseman
Copy link
Mannequin

milseman mannequin commented Jan 25, 2019

#22108

Will need release-noting as well.

@norio-nomura
Copy link
Contributor Author

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

@norio-nomura
Copy link
Contributor Author

Another example to fix an issue caused by wrong usage of encodedOffset.
apple/swift-corelibs-foundation#1894

@milseman
Copy link
Mannequin

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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant