官术网_书友最值得收藏!

Changed interpretation of grapheme clusters

An additional big advancement is the way String interprets grapheme clusters. Conformity of Unicode 9 gives resolution to this.

The use of extended grapheme clusters for character values in Swift 4 means that concatenation and modification of Strings may cause no affect on a resulting String's character count.

For example, if you append a COMBINING ACUTE ACCENT (U+0301) to the end of the String initialized to "cafe", the resulting String will have a character count of 4, and the fourth character will be "e", not e':

var word = "cafe"
print("total chars in \(word) is \(word.count)")

It prints "total chars in cafe is 4":

word += "\u{301}"    // COMBINING ACUTE ACCENT, U+0301
print("totalchars in \(word) is \(word.count)")

It prints "total chars in cafe? is 4", whereas the count would increase by 1 to reflect 5 as a result of print statement earlier.

Sequence of one or more Unicode scalars that when combined generate a single human-readable character is known as an extended grapheme cluster.

Similar to Dictionaries, the total number of modifications made to String API can be summed up by the following image:

主站蜘蛛池模板: 安陆市| 商南县| 大理市| 卢龙县| 酒泉市| 天祝| 墨竹工卡县| 同江市| 华坪县| 伊川县| 赤峰市| 达日县| 星座| 南开区| 松滋市| 樟树市| 安康市| 依兰县| 宁津县| 温宿县| 宁津县| 崇州市| 新河县| 周宁县| 民和| 苍溪县| 武邑县| 长治市| 霍山县| 汨罗市| 沐川县| 津市市| 平邑县| 诸暨市| 镇江市| 寿光市| 四会市| 曲阜市| 达州市| 彝良县| 潮安县|