summaryrefslogtreecommitdiffstats
path: root/bridge/irc/charset.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-03-19 23:14:56 +0100
committerGitHub <noreply@github.com>2022-03-19 23:14:56 +0100
commitf0f801402d95b1f49018fa9af77c341ff4c4de5f (patch)
treed7ba0f532c2a9accf702d3347d2efba725e4419f /bridge/irc/charset.go
parent663850a2b825e762667f930cd5a4ee87de853444 (diff)
downloadmatterbridge-msglm-f0f801402d95b1f49018fa9af77c341ff4c4de5f.tar.gz
matterbridge-msglm-f0f801402d95b1f49018fa9af77c341ff4c4de5f.tar.bz2
matterbridge-msglm-f0f801402d95b1f49018fa9af77c341ff4c4de5f.zip
Refactor utf-8 conversion (irc) (#1767)
Diffstat (limited to 'bridge/irc/charset.go')
-rw-r--r--bridge/irc/charset.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/bridge/irc/charset.go b/bridge/irc/charset.go
new file mode 100644
index 00000000..57872ec9
--- /dev/null
+++ b/bridge/irc/charset.go
@@ -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
+}