为什么.ord不同意.chars?

时间:2016-09-20 20:47:15

标签: unicode perl6

我对.chars的理解是它返回"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)。更令人困惑的是,如果你在LATIN SMALL LETTER E和COMBINING ACUTE ACCENT上调用.ords,你会回到U + 00e9(LATIN SMALL LETTER E WITH ACUTE)。我期待U + 0065,因为LATIN SMALL LETTER E是基本代码点。当没有NFC版本的字符串时,我确实得到了预期的结果(例如U + 0030为0)。

我对.chars.ords的理解是否有缺陷,或者这是一个错误?

1 个答案:

答案 0 :(得分:7)

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

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

该网站很快就会出现。

相关问题