-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor utf-8 conversion (irc) (#1767)
- Loading branch information
Showing
11 changed files
with
719 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package birc | ||
|
||
import ( | ||
"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" | ||
) | ||
|
||
var encoders = map[string]encoding.Encoding{ | ||
"utf-8": unicode.UTF8, | ||
"iso-2022-jp": japanese.ISO2022JP, | ||
"big5": traditionalchinese.Big5, | ||
"gbk": simplifiedchinese.GBK, | ||
"euc-kr": korean.EUCKR, | ||
"gb2312": simplifiedchinese.HZGB2312, | ||
"shift-jis": japanese.ShiftJIS, | ||
"euc-jp": japanese.EUCJP, | ||
"gb18030": simplifiedchinese.GB18030, | ||
} | ||
|
||
func toUTF8(from string, input string) string { | ||
enc, ok := encoders[from] | ||
if !ok { | ||
return input | ||
} | ||
|
||
res, _ := enc.NewDecoder().String(input) | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.