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

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:

主站蜘蛛池模板: 灵丘县| 定边县| 梓潼县| 留坝县| 泸水县| 黄大仙区| 高雄市| 长宁区| 鞍山市| 中阳县| 定日县| 龙井市| 宜君县| 洪江市| 唐海县| 依安县| 洞头县| 城固县| 惠安县| 庄河市| 阳泉市| 饶平县| 昆山市| 勐海县| 石屏县| 和龙市| 黔江区| 朔州市| 商洛市| 沂水县| 湛江市| 石狮市| 皮山县| 高雄县| 宁阳县| 彭泽县| 滨海县| 岱山县| 浮山县| 高要市| 增城市|