OGeek|极客世界-中国程序员成长平台

标题: ios - 在 iOS 上处理的表情符号序列不一致? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:23
标题: ios - 在 iOS 上处理的表情符号序列不一致?

在 iOS 和 macOS 上,regional indicator symbols 的序列被渲染为国旗表情符号,如果序列无效,则显示实际符号:

Plain regional indicator symbols.

但是,如果序列恰好包含一对未映射到标志表情符号的区域指示符号,则潜在标志将在首次匹配的基础上呈现:

Some funky rendering.

iOS/macOS 渲染符号:F F I S E S.

在 Swift 3 中,连续的区域指示符符号都集中在一个 Character 中,这意味着一个 Character 对象可以包含理论上无限量的 UnicodeScalar 对象,只要它们都是区域指标符号。本质上,Swift 3 根本没有破坏区域指示符。

另一方面,在 Swift 4 中,一个 Character 对象在其 Unicode 标量表示中最多包含两个区域指示符符号。此外,可以理解的是,没有考虑序列的有效性,因此区域指示符符号序列在每两个标量处被简单地分解,并被视为一个 Character。现在,迭代与上面相同的字符串并打印每个字符会产生以下结果:

Some other funky rendering.

包含以下符号的 Swift 4 字符串:F F I S E S.

这给我们带来了实际的问题——iOS 和 macOS 如何呈现序列,或者 Swift 4 如何在字符串中构造 Character 表示的问题?

我很好奇哪一方最适合向其报告这种特殊性。


以下是 Swift 4 中行为的最小可重现片段:

// Regional indicator symbols F F I S E S
var string = "\u{1f1eb}\u{1f1eb}\u{1f1ee}\u{1f1f8}\u{1f1ea}\u{1f1f8}"

for character in string {
    print(character)
}



Best Answer-推荐答案


经过一番调查,似乎两者都没有错,尽管在 Swift 4 中实现的方法更符合建议。

根据 Unicode 标准(强调我的):

The representative glyph for a single regional indicator symbol is just a dotted box containing a capital Latin letter. The Unicode Standard does not prescribe how the pairs of regional indicator symbols should be rendered. However, current industry practice widely interprets pairs of regional indicator symbols as representing a flag associated with the corresponding ISO 3166 region code.

The Unicode Standard, Version 10.0 – Core Specification, page 836.

然后,在以下页面上:

Conformance to the Unicode Standard does not require conformance to UTS #51. However, the interpretation and display of pairs of regional indicator symbols as specified in UTS #51 is now widely deployed, so in practice it is not advisable to attempt to interpret pairs of regional indicator symbols as representing anything other than an emoji flag.

– The Unicode Standard, Version 10.0 – Core Specification, page 837.

据我所知,虽然标准没有为如何渲染标志设置任何规则,但在 iOS 和 macOS 中处理无效标志序列的渲染所选择的路径是不可取的。因此,即使序列中进一步存在有效标志,渲染器也应始终将两个连续的区域指示符视为标志。

最后,看看 UTS #51,或“表情符号规范”:

Options for presenting an emoji_flag_sequence for which a system does not have a specific flag or other glyph include:

Missing flag glyph.

Unicode Technical Standard #51, revision 12 , 附录 B。

因此,总而言之,最佳实践是将无效标志序列表示为一对区域指示符符号 - 与 Swift 4 字符串中的 Character 对象完全相同 - 或作为通用 缺少标志字形。

关于ios - 在 iOS 上处理的表情符号序列不一致?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47536874/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4