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

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:

主站蜘蛛池模板: 新巴尔虎左旗| 师宗县| 巢湖市| 永德县| 轮台县| 大关县| 武隆县| 临澧县| 洪湖市| 兰坪| 开鲁县| 罗城| 浦县| 衢州市| 历史| 岳阳县| 芮城县| 边坝县| 蕲春县| 奈曼旗| 潢川县| 吴桥县| 日喀则市| 徐闻县| 沿河| 开封县| 平利县| 金华市| 施甸县| 金塔县| 永和县| 金寨县| 渑池县| 龙陵县| 高阳县| 德兴市| 凯里市| 湄潭县| 城固县| 安徽省| 鸡西市|