fix: use string slice for CHARS to handle UTF-8 multibyte chars correctly
Build and Deploy / build (push) Successful in 2m43s
Build and Deploy / deploy (push) Successful in 9s

This commit is contained in:
2026-07-17 12:43:17 +00:00
parent 5a86d68228
commit f7cfc4a888
+10 -10
View File
@@ -421,12 +421,14 @@ func decodeMathFromOutput(output []float32) string {
}
}
CHARS := "0123456789+-*/÷×=?"
// 字符集:索引 1-18 对应字符
// 注意:使用 slice 而不是 string,避免 UTF-8 多字节字符的索引问题
CHARS := []string{"", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", "÷", "×", "=", "?"}
// DEBUG: 打印字符集每个字符的索引和 rune 值
fmt.Printf("DEBUG CHARS: ")
// DEBUG: 打印字符集
fmt.Printf("DEBUG CHARS slice (len=%d): ", len(CHARS))
for i, c := range CHARS {
fmt.Printf("[%d]=%c(rune:%d) ", i+1, c, c)
fmt.Printf("[%d]=%s ", i, c)
}
fmt.Println()
@@ -449,10 +451,8 @@ func decodeMathFromOutput(output []float32) string {
// 打印所有位置的识别结果(包括索引值)
debugStr := "DEBUG argmax: "
for _, idx := range allChars {
if idx > 0 && idx <= len(CHARS) {
debugStr += fmt.Sprintf("%c", CHARS[idx-1])
} else if idx == 0 {
debugStr += "_"
if idx >= 0 && idx < len(CHARS) {
debugStr += CHARS[idx]
} else {
debugStr += fmt.Sprintf("[%d]", idx) // 显示越界索引
}
@@ -467,8 +467,8 @@ func decodeMathFromOutput(output []float32) string {
lastIdx := -1
for _, idx := range allChars {
if idx != 0 && idx != lastIdx {
if idx-1 < len(CHARS) {
result += string(CHARS[idx-1])
if idx < len(CHARS) {
result += CHARS[idx]
}
}
lastIdx = idx