[SR-9749] The encodedOffset of String.Index has been changed to either UTF-8 or UTF-16. #52180
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
standard library
Area: standard library umbrella
Environment
swift-DEVELOPMENT-SNAPSHOT-2019-01-23-a
swift-5.0-DEVELOPMENT-SNAPSHOT-2019-01-23-a
Additional Detail from JIRA
md5: 66ece592c380ddd277127ea29c649351
Issue Description:
The problem is:
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.https://github.com/apple/swift/pull/20315/files#diff-8ec9c169d4bc3c678838b4067481979eL130
https://github.com/apple/swift/pull/20315/files#diff-8ec9c169d4bc3c678838b4067481979eL106
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=CodeHowever, 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:)
andencodedOffset
as deprecatedor
Introduce new property exposing encode information(UTF-8 or UTF-16) to
String
/cc: @milseman
The text was updated successfully, but these errors were encountered: