【问题标题】:Why does .ords not agree with .chars?为什么 .ords 不同意 .chars?
【发布时间】:2017-01-28 22:20:08
【问题描述】:

我对@9​​87654323@的理解是它返回"the number of characters in the string in graphemes"。我对.ords 的理解是它返回"a list of codepoint numbers, one for the base character of each grapheme in the string"。也就是说,.chars 返回字素的数量,.ords 每个字素返回一个代码点(基数)。但是,我在 MoarVM 2016.07 上的 Rakudo 2016.07.1 中看到的行为似乎与此不符:

> "\x[2764]\x[fe0e]".chars
1
> "\x[2764]\x[fe0e]".ords.fmt("U+%04x")
U+2764 U+fe0e
> "e\x[301]".ords.fmt("U+%04x")
U+00e9
> "0\x[301]".ords.fmt("U+%04x")
U+0030

.chars 方法返回 HEAVY BLACK HEART 和 VARIATION SELECTOR-15 的期望 1(文本表示 ❤︎ 而不是表情符号❤️,U+2764 U+fe0f),但随后 .ords 返回两个代码点,而不仅仅是基础(我预计只有 U+2764)。更令人困惑的是,如果您在拉丁文小写字母 E 上调用 .ords 并结合锐音,您会得到 U+00e9(拉丁文小写字母 E 与锐音)。我期待 U+0065 因为 LATIN SMALL LETTER E 是基本代码点。当没有 NFC 版本的字符串时,我确实得到了预期的结果(例如 U+0030 表示 0́)。

我对@9​​87654331@ 和.ords 的理解只是有缺陷,还是这是一个错误?

【问题讨论】:

  • 看起来像一个错误。

标签: unicode raku


【解决方案1】:

关于 .ords 方法的文档错误。一位核心开发人员刚刚使用此提交更新了文档:

https://github.com/perl6/doc/commit/12ec5fc35e

很快就会出现在网站上。

【讨论】:

    猜你喜欢
    • 2010-12-19
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 2020-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多