菜鸟教程小白 发表于 2022-12-11 19:23:20

ios - 在 iOS 上处理的表情符号序列不一致?


                                            <p><p>在 iOS 和 macOS 上,<a href="https://en.wikipedia.org/wiki/Regional_Indicator_Symbol" rel="noreferrer noopener nofollow">regional indicator symbols</a> 的序列被渲染为国旗表情符号,如果序列无效,则显示实际符号:</p>

<p> <a href="/image/jQI8x.png" rel="noreferrer noopener nofollow"><img src="/image/jQI8x.png" alt="Plain regional indicator symbols."/></a> </p>

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

<p> <a href="/image/qhECt.png" rel="noreferrer noopener nofollow"><img src="/image/qhECt.png" alt="Some funky rendering."/></a> </p>

<p><sup>iOS/macOS 渲染符号:F F I S E S.</sup></p>

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

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

<p> <a href="/image/3dtqg.png" rel="noreferrer noopener nofollow"><img src="/image/3dtqg.png" alt="Some other funky rendering."/></a> </p>

<p><sup>包含以下符号的 Swift 4 字符串:F F I S E S.</sup></p>

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

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

<hr/>

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

<pre><code>// Regional indicator symbols F F I S E S
var string = &#34;\u{1f1eb}\u{1f1eb}\u{1f1ee}\u{1f1f8}\u{1f1ea}\u{1f1f8}&#34;

for character in string {
    print(character)
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>经过一番调查,似乎两者都没有错,尽管在 Swift 4 中实现的方法更符合建议。</p>
<p>根据 Unicode 标准(强调我的):</p>
<blockquote>
<p>The representative glyph for a single regional indicator symbol is just a dotted box containing a capital Latin letter. The Unicode Standard <strong>does not prescribe how the pairs of regional indicator symbols should be rendered</strong>. However, current industry practice widely interprets pairs of regional indicator symbols as representing a flag associated with the corresponding ISO 3166 region code.</p>
<p>– <a href="https://www.unicode.org/versions/Unicode10.0.0/UnicodeStandard-10.0.pdf" rel="noreferrer noopener nofollow">The Unicode Standard, Version 10.0 – Core Specification</a>, page 836.</p>
</blockquote>
<p>然后,在以下页面上:</p>
<blockquote>
<p>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 <strong>in practice it is not advisable to attempt to interpret pairs of regional indicator symbols as representing anything other than an emoji flag</strong>.</p>
<p>– The Unicode Standard, Version 10.0 – Core Specification, page 837.</p>
</blockquote>
<p>据我所知,虽然标准没有为如何渲染标志设置任何规则,但在 iOS 和 macOS 中处理无效标志序列的渲染所选择的路径是不可取的。因此,即使序列中进一步存在有效标志,渲染器也应始终将两个连续的区域指示符视为标志。</p>
<p>最后,看看 UTS #51,或“表情符号规范”:</p>
<blockquote>
<p>Options for presenting an emoji_flag_sequence for which a system does not have a specific flag or other glyph include:</p>
<ul>
<li><p><strong>Displaying each REGIONAL INDICATOR symbol separately as a letter in a dotted square, as shown in the Unicode charts</strong>. This provides information about the specific region indicated, but may be mystifying to some users.</p>
</li>
<li><p><strong>For all unsupported REGIONAL INDICATOR pairs, displaying the same “missing flag” glyph, such as the image shown below</strong>. This would indicate that the supported pair was intended to represent the flag of some region, without indicating which one.</p>
</li>
</ul>
<blockquote>
<p><a href="/image/fp130.png" rel="noreferrer noopener nofollow"><img src="/image/fp130.png" alt="Missing flag glyph."/></a></p>
</blockquote>
<p>– <a href="https://www.unicode.org/reports/tr51/tr51-12.html" rel="noreferrer noopener nofollow">Unicode Technical Standard #51, revision 12</a> , 附录 B。</p>
</blockquote>
<p>因此,总而言之,最佳实践是将无效标志序列表示为一对区域指示符符号 - 与 Swift 4 字符串中的 <code>Character</code> 对象完全相同 - 或作为通用 <em >缺少标志</em>字形。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在 iOS 上处理的表情符号序列不一致?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/47536874/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/47536874/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在 iOS 上处理的表情符号序列不一致?