HotCRC内的HexToHotCode()源码(菜农自创万国字符编码)
本帖最后由 hotpower 于 2023-9-23 10:37 编辑菜农电子淘宝:https://hotcomlock.taobao.com/ 准备出书:http://hotcomlock.com/hotcomlock.html
HotCode汉字编码(V1.0)是菜农对UniCode编码(V5.0)的汉字简化版本:
1.用0080-00ff替换2580-25ff方块元素几何图形。
2.用f900-faff替换2c00-2dff格拉哥里字母等。
3.用fe30-fe4f替换9fc0-9fdf未定义。
4.用ff00-ffff替换2800-28ff盲文点字模型。
HotCode选中unicode2000-9fff为编码范围,
然后加6000,使HotCode编码范围为8000-ffff,ascii码为00-7f。
HotCode编码汉字为两字节,字符为单字节。
function HexToHotCode(hexstr) {
var str,hotcodestr;
var i, num;
hotcodestr = "";
i = 0;
while(i < hexstr.length) {
str = hexstr.substr(i, 2);
num = hextoint(str);
if (num < 0x80) {//
if(num == 0) break;//0字符不解码
hotcodestr += String.fromCharCode(num);
i += 2;
}
else {
str = hexstr.substr(i, 4);
num = hextoint(str);
num -= 0x6000;
if (num > 0x2580 && num <= 0x25ff) {
num -= (0x2580 - 0x0080);
}
else {
if (num > 0x2800 && num <= 0x28ff) {
num -= (0x2800 - 0xff00);
}
else if (num > 0x9fc0 && num <= 0x9fdf) {
num -= (0x9fc0 - 0xfe30);
}
else if (num > 0x2c00 && num <= 0x2dff) {
num -= (0x2c00 - 0xf900);
}
}
hotcodestr += String.fromCharCode(num);
i += 4;
}
}
return hotcodestr;
}
https://bbs.21ic.com/data/attachment/forum/202309/22/101124qp474qggq7ix7pjx.jpg.thumb.jpg
页:
[1]