gpt4 book ai didi

unicode - Unicode NFC 规范化可以增加字符串的长度吗?

转载 作者:行者123 更新时间:2023-12-01 09:59:53 24 4
gpt4 key购买 nike

如果我将 Unicode 规范化形式 C 应用于字符串,字符串中的代码点数量是否会增加?

最佳答案

是的,有些代码点在应用 NFC 标准化后扩展为多个代码点。 Basic Multilingual Plane内,例如应用NFC归一化后有70个码位扩展为2个码位,有2个码位(Alphabetic Presentation Forms block内的U+FB2C和U+FB2D)扩展为3个码位。

您对这个所谓的“扩展因子”的一个保证是,在应用 NFC 规范化后,任何字符串的长度都不会扩展超过 3 倍(根据 code units 的数量):

There is also a Unicode Consortium stability policy that canonical mappings are always limited in all versions of Unicode, so that no string when decomposed with NFC expands to more than 3× in length (measured in code units). This is true whether the text is in UTF-8, UTF-16, or UTF-32. This guarantee also allows for certain optimizations in processing, especially in determining buffer sizes.

第 9 节,Detecting Normalization Forms . UAX #15:Unicode 规范化形式。

我编写了一个 Java 程序来确定 Unicode block 中的哪些代码点扩展为多个代码点:http://ideone.com/9PUOCb

或者,Tom Christiansenunichars实用程序,Unicode::Tussle CPAN 模块的一部分,可以使用。 (注意:Mac 用户可能会在 make test 安装步骤看到错误,提示 Perl 版本太旧。如果看到此错误,您可以通过运行 notest install Unicode 安装模块::Tussle 在 CPAN shell 中。)

例子:

  • 打印 BMP 中扩展为 3 个代码点的代码点:

    unichars 'length(NFC) == 3'
    ‭‭ שּׁ  U+FB2C HEBREW LETTER SHIN WITH DAGESH AND SHIN DOT‭ שּׂ  U+FB2D HEBREW LETTER SHIN WITH DAGESH AND SIN DOT
  • 统计扩展到多个码位的所有平面中的码位数量:

    unichars -a 'length(NFC) > 1' | wc -l
          85

另请参阅常见问题 What are the maximum expansion factors for the different normalization forms?

关于unicode - Unicode NFC 规范化可以增加字符串的长度吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17897534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com