зеркало из https://github.com/github/gh-ost.git
Extracted and generalized encoding logic to encoding.go
This commit is contained in:
Родитель
dc3a03ad6f
Коммит
f4693274fb
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
Copyright 2016 GitHub Inc.
|
||||
See https://github.com/github/gh-ost/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
"golang.org/x/text/encoding"
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
)
|
||||
|
||||
type charsetEncoding map[string]encoding.Encoding
|
||||
|
||||
var charsetEncodingMap charsetEncoding
|
||||
|
||||
func init() {
|
||||
charsetEncodingMap = make(map[string]encoding.Encoding)
|
||||
// Begin mappings
|
||||
charsetEncodingMap["latin1"] = charmap.Windows1252
|
||||
}
|
|
@ -10,8 +10,6 @@ import (
|
|||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/encoding/charmap"
|
||||
)
|
||||
|
||||
type Column struct {
|
||||
|
@ -22,9 +20,9 @@ type Column struct {
|
|||
|
||||
func (this *Column) convertArg(arg interface{}) interface{} {
|
||||
if s, ok := arg.(string); ok {
|
||||
switch this.Charset {
|
||||
case "latin1":
|
||||
arg, _ = charmap.Windows1252.NewDecoder().String(s)
|
||||
// string, charset conversion
|
||||
if encoding, ok := charsetEncodingMap[this.Charset]; ok {
|
||||
arg, _ = encoding.NewDecoder().String(s)
|
||||
}
|
||||
return arg
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче