-
Notifications
You must be signed in to change notification settings - Fork 74
refactor: deduplicate charset encode/decode into shared lookup map #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package firebirdsql | ||
|
|
||
| import ( | ||
| "golang.org/x/text/encoding" | ||
| "golang.org/x/text/encoding/charmap" | ||
| "golang.org/x/text/encoding/japanese" | ||
| "golang.org/x/text/encoding/korean" | ||
| "golang.org/x/text/encoding/simplifiedchinese" | ||
| "golang.org/x/text/encoding/traditionalchinese" | ||
| ) | ||
|
|
||
| func charsetEncoding(charset string) encoding.Encoding { | ||
| switch charset { | ||
| case "SJIS_0208": | ||
| return japanese.ShiftJIS | ||
| case "EUCJ_0208": | ||
| return japanese.EUCJP | ||
| case "ISO8859_1": | ||
| return charmap.ISO8859_1 | ||
| case "ISO8859_2": | ||
| return charmap.ISO8859_2 | ||
| case "ISO8859_3": | ||
| return charmap.ISO8859_3 | ||
| case "ISO8859_4": | ||
| return charmap.ISO8859_4 | ||
| case "ISO8859_5": | ||
| return charmap.ISO8859_5 | ||
| case "ISO8859_6": | ||
| return charmap.ISO8859_6 | ||
| case "ISO8859_7": | ||
| return charmap.ISO8859_7 | ||
| case "ISO8859_8": | ||
| return charmap.ISO8859_8 | ||
| case "ISO8859_9": | ||
| return charmap.ISO8859_9 | ||
| case "ISO8859_13": | ||
| return charmap.ISO8859_13 | ||
| case "KSC_5601": | ||
| return korean.EUCKR | ||
| case "WIN1250": | ||
| return charmap.Windows1250 | ||
| case "WIN1251": | ||
| return charmap.Windows1251 | ||
| case "WIN1252": | ||
| return charmap.Windows1252 | ||
| case "WIN1253": | ||
| return charmap.Windows1253 | ||
| case "WIN1254": | ||
| return charmap.Windows1254 | ||
| case "BIG_5": | ||
| return traditionalchinese.Big5 | ||
| case "GB_2312": | ||
| return simplifiedchinese.HZGB2312 | ||
| case "WIN1255": | ||
| return charmap.Windows1255 | ||
| case "WIN1256": | ||
| return charmap.Windows1256 | ||
| case "WIN1257": | ||
| return charmap.Windows1257 | ||
| case "KOI8R": | ||
| return charmap.KOI8R | ||
| case "KOI8U": | ||
| return charmap.KOI8U | ||
| case "WIN1258": | ||
| return charmap.Windows1258 | ||
| default: | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| func decodeCharset(raw []byte, charset string) (string, bool) { | ||
| enc := charsetEncoding(charset) | ||
| if enc == nil { | ||
| return "", false | ||
| } | ||
|
Comment on lines
+71
to
+75
|
||
| v, _ := enc.NewDecoder().Bytes(raw) | ||
| return string(v), true | ||
| } | ||
|
|
||
| func encodeCharset(str string, charset string) (string, bool) { | ||
| enc := charsetEncoding(charset) | ||
| if enc == nil { | ||
| return "", false | ||
| } | ||
| v, _ := enc.NewEncoder().String(str) | ||
| return v, true | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New file
charset.gois missing the repository’s standard MIT license header comment block that appears at the top of most non-test.gofiles (e.g.,xsqlvar.go,wireprotocol.go). Please add the same header here to keep file headers consistent.