swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.29k stars 10.33k forks source link

[SR-367] Regional Indicator letters & flags: prefix and suffix #42986

Closed glessard closed 4 years ago

glessard commented 8 years ago
Previous ID SR-367
Radar None
Original Reporter @glessard
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Standard Library | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 42c209e3a14e2350b7530adf1f1fb8ba

Issue Description:

In the presence of Objective-C, hasPrefix and hasSuffix have the wrong behaviour.

let b1 = "\u{1F1E7}" // Regional indicator letter B
let b2 = b1+b1       // flag of Barbados

b2.hasPrefix(b1) // returns true
b2.hasSuffix(b1) // returns true

According to Unicode rules, the grapheme cluster from string b1 is not present in string b2, as there is should be no grapheme cluster break between the two instances of \u{1F1E7} in b2. (http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules).
Both functions should return false in the example above.

dabrahams commented 7 years ago

This problem is being fixed in the new String design, FWIW.

airspeedswift commented 6 years ago

Should be resolved by https://github.com/apple/swift-corelibs-foundation/pull/1459/

glessard commented 6 years ago

This is fixed in Swift 4.2, as expected