diff --git a/g/encoding/gcharset/gcharset.go b/g/encoding/gcharset/gcharset.go index 4a2490759..b2829e25b 100644 --- a/g/encoding/gcharset/gcharset.go +++ b/g/encoding/gcharset/gcharset.go @@ -18,15 +18,6 @@ import ( ) - -//获取支持的字符集 -func GetCharset(name string) (*mahonia.Charset, error) { - s := mahonia.GetCharset(name) - if s == nil { - return nil, errors.New(fmt.Sprintf("not support charset: %s", name)) - } - return s, nil -} //2个字符集之间的转换 func Convert(dstCharset string, srcCharset string, src string) (dst string, err error) { s := mahonia.GetCharset(srcCharset) diff --git a/g/encoding/gxml/gxml.go b/g/encoding/gxml/gxml.go index 04ef17bb7..b155a1045 100644 --- a/g/encoding/gxml/gxml.go +++ b/g/encoding/gxml/gxml.go @@ -11,8 +11,10 @@ import ( "github.com/clbanning/mxj" "encoding/xml" "io" - "gitee.com/johng/gf/g/encoding/gcharset" "gitee.com/johng/gf/g/util/gregx" + "github.com/axgle/mahonia" + "errors" + "fmt" ) // 将XML内容解析为map变量 @@ -47,9 +49,9 @@ func ToJson(xmlbyte []byte) ([]byte, error) { func Prepare(xmlbyte []byte) error { patten := "<\\?xml\\s+version\\s*=.*?\\s+encoding\\s*=\\s*[\\'|\"](.*?)[\\'|\"]\\s*\\?\\s*>" charsetReader := func(charset string, input io.Reader) (io.Reader, error) { - reader, err := gcharset.GetCharset(charset) - if err != nil { - return nil, err + reader := mahonia.GetCharset(charset) + if reader == nil { + return nil, errors.New(fmt.Sprintf("not support charset:%s", charset)) } return reader.NewDecoder().NewReader(input), nil } @@ -59,9 +61,9 @@ func Prepare(xmlbyte []byte) error { return err } - charset, err := gcharset.GetCharset(matchStr[1]) - if err != nil { - return err + charset := mahonia.GetCharset(matchStr[1]) + if charset == nil { + return errors.New(fmt.Sprintf("not support charset:%s", matchStr[1])) } if charset.Name != "UTF-8" {