获取 JavaScript 中给定字符串的 4 种不同形式的阿拉伯语 Unicode 字符(首字母、中间字母、结尾字母或独立字母)
Get 4 distinct forms (initial, medial, final or isolated) of Arabic Unicode characters of the given string in JavaScript
我有阿拉伯语内容,例如 ضضضضضضض。我想获取给定字符串中所有形式的字母(首字母、中间字母、结尾字母或孤立字母)的 Unicode 代码点。
Javascript 图书馆(不是我的)可以为您做这件事:https://github.com/louy/Javascript-Arabic-Reshaper
这将采用一个仅使用 'generic' 个字符的字符串,并 return 为您提供一个新字符串,并为您完成所有正确的特定于位置的替换。从那里,您可以在每个位置获取字符代码(或代码点)。
这是一个示例用法:
//import the library
var ArabicReshaper = require('arabic-reshaper');
// This can be a plain string. I just want to make sure I am feeding
// it the "plain" letter, not the initial/middle/end forms
var originalString = String.fromCharCode(0x0636, 0x0636); //ضض
// this will convert it to the 'shaped' letters. that means the letters
// will be transformed into the 'initial/middle/end' forms in the string
// (not just when it draws to the screen.
var newString = ArabicReshaper.convertArabic(originalString);
// And get the values. These will be the specific initial/middle/end values, not the generic ones
console.log(
newString.codePointAt(0).toString(16), // outputs febf
newString.codePointAt(1).toString(16) // outputs febe
);
我有阿拉伯语内容,例如 ضضضضضضض。我想获取给定字符串中所有形式的字母(首字母、中间字母、结尾字母或孤立字母)的 Unicode 代码点。
Javascript 图书馆(不是我的)可以为您做这件事:https://github.com/louy/Javascript-Arabic-Reshaper
这将采用一个仅使用 'generic' 个字符的字符串,并 return 为您提供一个新字符串,并为您完成所有正确的特定于位置的替换。从那里,您可以在每个位置获取字符代码(或代码点)。
这是一个示例用法:
//import the library
var ArabicReshaper = require('arabic-reshaper');
// This can be a plain string. I just want to make sure I am feeding
// it the "plain" letter, not the initial/middle/end forms
var originalString = String.fromCharCode(0x0636, 0x0636); //ضض
// this will convert it to the 'shaped' letters. that means the letters
// will be transformed into the 'initial/middle/end' forms in the string
// (not just when it draws to the screen.
var newString = ArabicReshaper.convertArabic(originalString);
// And get the values. These will be the specific initial/middle/end values, not the generic ones
console.log(
newString.codePointAt(0).toString(16), // outputs febf
newString.codePointAt(1).toString(16) // outputs febe
);