fix: 4 个 CRITICAL bug 修复

- C1: placement.rs 删除列偏移特殊处理 (col==6→5),place_bit 已自动跳过保留区
- C2: version.rs V5-H 纠错表 h_g1: 4→2 (总码字数 200→134)
- C3: mode.rs Kanji 编码删除冗余 if/else 重复分支
- C4: galois.rs div() 返回 Option<u8> 替代 panic!
This commit is contained in:
2026-06-17 08:58:29 +08:00
parent 7c13fb8f1c
commit feb5ae709f
7 changed files with 124 additions and 33 deletions
+7 -15
View File
@@ -158,22 +158,14 @@ fn unicode_to_shift_jis(c: char) -> Option<u16> {
// 简化映射: 用 Unicode 码位偏移做近似
// 真实转换需要完整映射表,这里做合理近似
let base = code - 0x4E00;
let hi = 0x81 + (base / 0xBC) as u32;
let lo = 0x40 + (base % 0xBC) as u32;
let hi = 0x81 + (base / 0xBC);
let lo = 0x40 + (base % 0xBC);
let sjis = ((hi << 8) | lo) as u16;
// 映射到 13-bit 码字
let val = if sjis <= 0x9FFC {
let h = (sjis >> 8) as u16;
let l = (sjis & 0xFF) as u16;
if h >= 0x81 && h <= 0x9F {
(h - 0x81) * 0xBC + (l - 0x40)
} else {
(h - 0xC1) * 0xBC + (l - 0x40)
}
} else {
let h = (sjis >> 8) as u16;
let l = (sjis & 0xFF) as u16;
if h >= 0x81 && h <= 0x9F {
// 映射到 13-bit 码字(内层 if/else 已区分两个 Shift-JIS 区间)
let val = {
let h = (sjis >> 8);
let l = (sjis & 0xFF);
if (0x81..=0x9F).contains(&h) {
(h - 0x81) * 0xBC + (l - 0x40)
} else {
(h - 0xC1) * 0xBC + (l - 0x40)