| 1 | package birc |
| 2 | |
| 3 | import ( |
| 4 | "golang.org/x/text/encoding" |
| 5 | "golang.org/x/text/encoding/japanese" |
| 6 | "golang.org/x/text/encoding/korean" |
| 7 | "golang.org/x/text/encoding/simplifiedchinese" |
| 8 | "golang.org/x/text/encoding/traditionalchinese" |
| 9 | "golang.org/x/text/encoding/unicode" |
| 10 | ) |
| 11 | |
| 12 | var encoders = map[string]encoding.Encoding{ |
| 13 | "utf-8": unicode.UTF8, |
| 14 | "iso-2022-jp": japanese.ISO2022JP, |
| 15 | "big5": traditionalchinese.Big5, |
| 16 | "gbk": simplifiedchinese.GBK, |
| 17 | "euc-kr": korean.EUCKR, |
| 18 | "gb2312": simplifiedchinese.HZGB2312, |
| 19 | "shift-jis": japanese.ShiftJIS, |
| 20 | "euc-jp": japanese.EUCJP, |
| 21 | "gb18030": simplifiedchinese.GB18030, |
| 22 | } |
| 23 | |
| 24 | func toUTF8(from string, input string) string { |
| 25 | enc, ok := encoders[from] |
| 26 | if !ok { |
| 27 | return input |
| 28 | } |
| 29 | |
| 30 | res, _ := enc.NewDecoder().String(input) |
| 31 | return res |
| 32 | } |
| 33 | |