Xcode-beta (7A152u): Repeated Unicode Flags in a String Are a Single Character in Swift

Originator:john
Number:rdar://21786105 Date Originated:12-Jul-2015 02:23 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A152u)
Classification:Other Bug Reproducible:Always
 
Summary:
If you create a string that has the same unicode flag repeated three times, those three flags will be a single Character. This doesn’t seem to match the behavior described in the Swift Programming Language book:

“Every instance of Swift’s Character type represents a single extended grapheme cluster. An extended grapheme cluster is a sequence of one or more Unicode scalars that (when combined) produce a single human-readable character.”

Steps to Reproduce:
1. Create a string containing the following unicode code points: 1F1FA, 1F1F8, 1F1FA, 1F1F8, 1F1FA, 1F1F8
2. Access the first entry in that string’s character array

Expected Results:
It should be a single US flag

Actual Results:
It is three US flags

Regression:

Notes:
I’ve attached a playground demonstrating this behavior.

Comments

This is due to how flags are handled in Unicode itself. Not a bug in Swift, but a result of a poorly designed aspect of the Unicode standard.

By jake.petroules at July 12, 2015, 11:40 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!