-
Notifications
You must be signed in to change notification settings - Fork 15
/
charset.go
51 lines (48 loc) · 1.41 KB
/
charset.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package terminal
import (
"strings"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/encoding/korean"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/encoding/traditionalchinese"
"golang.org/x/text/encoding/unicode"
)
func GetCharset(charset string) encoding.Encoding {
switch strings.ToUpper(charset) {
case "GB18030":
return simplifiedchinese.GB18030
case "GB2312", "HZ-GB2312":
return simplifiedchinese.HZGB2312
case "GBK":
return simplifiedchinese.GBK
case "BIG5":
return traditionalchinese.Big5
case "EUC-JP":
return japanese.EUCJP
case "ISO2022JP":
return japanese.ISO2022JP
case "SHIFTJIS":
return japanese.ShiftJIS
case "EUC-KR":
return korean.EUCKR
case "UTF8", "UTF-8":
return encoding.Nop
case "UTF16-BOM", "UTF-16-BOM":
return unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
case "UTF16-BE-BOM", "UTF-16-BE-BOM":
return unicode.UTF16(unicode.BigEndian, unicode.UseBOM)
case "UTF16-LE-BOM", "UTF-16-LE-BOM":
return unicode.UTF16(unicode.LittleEndian, unicode.UseBOM)
case "UTF16", "UTF-16":
return unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)
case "UTF16-BE", "UTF-16-BE":
return unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)
case "UTF16-LE", "UTF-16-LE":
return unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
//case "UTF32", "UTF-32":
// return simplifiedchinese.GBK
default:
return nil
}
}