JavaScript中的Unicode组成

问题描述 投票:1回答:1

我正在寻找一种方法,可以将连字显示给用户时作为一个单位进行计数,例如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范围,分解并创建地图,但我希望有更好的方法。

javascript unicode arabic ligature
1个回答
0
投票

鉴于the ES2019 spec要求实现:

让ns为String值,它是将S标准化为https://unicode.org/reports/tr15/中指定的以f命名的标准化形式的结果。

并且考虑到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)

无规范化将c4c5格式转换回c1c2c3

因此,根据我的unicode-amateur的意见,没有标准化的方法可以将U+0644 U+0627标准化回U+FEFB

© www.soinside.com 2019 - 2024. All rights reserved.