2

我正在寻找一种方法来将连字计算为单个单元,因为它们显示给用户,例如https://www.compart.com/en/unicode/U+FEFB

当输入这个字符时(在阿拉伯语键盘上输入 G),它以分解形式插入,即U+0644 U+0627.

我可以U+FEFB分解

escape(String.fromCodePoint(0xFEFB).normalize("NFKD")) // '%u0644%u0627'

有没有办法U+0644 U+0627组成0xFEFB

为什么这行得通?

escape(String.fromCodePoint(0x0644, 0x0627).normalize("NFKC"))

我唯一的想法是遍历我感兴趣的 unicode 范围,分解并创建地图,但我希望有更好的方法。

4

1 回答 1

2

鉴于ES2019 规范要求实现:

令 ns 为字符串值,它是将 S 标准化为由 f 命名的标准化形式的结果,如https://unicode.org/reports/tr15/中指定的那样。

并鉴于https://www.unicode.org/Public/12.1.0/ucd/NormalizationTest.txt将该字符描述为

FEFB;FEFB;FEFB;0644 0627;0644 0627; # (ﻻ; ﻻ; ﻻ; لا; لا; ) ARABIC LIGATURE LAM WITH ALEF ISOLATED FORM

这是合规行为。看

# 1. The following invariants must be true for all conformant implementations
#
#    NFC
#      c2 ==  toNFC(c1) ==  toNFC(c2) ==  toNFC(c3)
#      c4 ==  toNFC(c4) ==  toNFC(c5)
#
#    NFD
#      c3 ==  toNFD(c1) ==  toNFD(c2) ==  toNFD(c3)
#      c5 ==  toNFD(c4) ==  toNFD(c5)
#
#    NFKC
#      c4 == toNFKC(c1) == toNFKC(c2) == toNFKC(c3) == toNFKC(c4) == toNFKC(c5)
#
#    NFKD
#      c5 == toNFKD(c1) == toNFKD(c2) == toNFKD(c3) == toNFKD(c4) == toNFKD(c5)

没有标准化将c4orc5形式转换回c1, or c2, or c3

因此,在我的 unicode 业余爱好者看来,没有符合标准的方式来规范化U+0644 U+0627U+FEFB.

于 2019-11-14T21:40:48.287 回答