1 Star 0 Fork 0

topxeq / mahonia

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
euc-jp.go 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
TopXeQ 提交于 2019-08-28 14:06 . a 0.1
package mahonia
// Converters for the EUC-JP encoding
import (
"sync"
)
func init() {
RegisterCharset(&Charset{
Name: "EUC-JP",
Aliases: []string{"extended_unix_code_packed_format_for_japanese", "cseucpkdfmtjapanese"},
NewDecoder: func() Decoder {
eucJPOnce.Do(makeEUCJPTable)
return eucJPTable.Decoder()
},
NewEncoder: func() Encoder {
eucJPOnce.Do(makeEUCJPTable)
return eucJPTable.Encoder()
},
})
}
var eucJPOnce sync.Once
var eucJPTable MBCSTable
func makeEUCJPTable() {
var b [3]byte
b[0] = 0x8f
for jis0212, unicode := range jis0212ToUnicode {
if unicode == 0 {
continue
}
b[1] = byte(jis0212>>8) | 128
b[2] = byte(jis0212) | 128
eucJPTable.AddCharacter(rune(unicode), string(b[:3]))
}
for jis0208, unicode := range jis0208ToUnicode {
if unicode == 0 {
continue
}
b[0] = byte(jis0208>>8) | 128
b[1] = byte(jis0208) | 128
eucJPTable.AddCharacter(rune(unicode), string(b[:2]))
}
b[0] = 0x8e
for i := 128; i < 256; i++ {
unicode := jis0201ToUnicode[i]
if unicode == 0 {
continue
}
b[1] = byte(i)
eucJPTable.AddCharacter(rune(unicode), string(b[:2]))
}
for i := '\x00'; i < 128; i++ {
var unicode rune
if i < 32 || i == 127 {
unicode = i
} else {
unicode = rune(jis0201ToUnicode[i])
if unicode == 0 {
continue
}
}
eucJPTable.AddCharacter(unicode, string(byte(i)))
}
}
Go
1
https://gitee.com/topxeq/mahonia.git
git@gitee.com:topxeq/mahonia.git
topxeq
mahonia
mahonia
master

搜索帮助